Ads are not showing up in release mode
Solution 1
Create a file called proguard-rules.pro in your android/app directory.
Add this line of code to it:
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-keep class com.google.firebase.** { *; }
-keep class com.shatsy.** { *; }
The most important being: -keep class com.google.firebase.** { *; }
and -keep class com.shatsy.** { *; }
Now in your app level build.gradle file, add this to your buildType:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
So that your buildType folder looks something like this:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
Then run flutter build apk --buildTypeName
Example:
flutter build apk --release
A quicker solution is to add minifyEnabled false
to your release buildType in you app level build.gradle
EXPLANATION: Proguard is probably blocking your app from using the firebase_ads library. That's probably why your app runs in debug mode, but not after building the apk.
Try it, and see if it works.
Solution 2
It takes a few hours to show ads on the release version. So if it is working on debug apk then you don't need to add any bit of code, just update your account details on AdMob and wait for account confirmation and you will see ads on release after few hours.
Solution 3
I had problems with the same and that was my error, I did not add the internet permission. Add the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app.
Step 1: Go to android\app\src\main\AndroidManifest.xml
Step 2: Copy this line below:
<uses-permission android:name="android.permission.INTERNET" />
Step 3: Put it in AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.java2blog.helloworldapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HelloWorldActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 4: Rebuild the the .apk and try on mobile it should work.
Comments
-
Aman Verma over 1 year
Ads not showing up in release mode
i want to try the solution mentioned here but i dont know how to
when the app is signed in debug it shows ads , but not in release mode
-
Wilson Wilson almost 4 yearsWhat package are you using for ads? firebase_admob, admob_flutter, or both?
-
Aman Verma almost 4 yearsboth , firebase_admob for interstial ad , and admob_flutter for banner
-
Wilson Wilson almost 4 yearsI've edited my answer. Added (-keep class com.shatsy.** { *; })
-
Ray Coder over 3 yearsShould we use firebase_admob and admob_flutter? Or can we just use admob_flutter? and why we should use firebase_admob? I mean in what case? @WilsonWilson
-
-
Aman Verma almost 4 yearsshould i let it remain in debug mode as you have left
-
Wilson Wilson almost 4 yearsIt depends on what you're currently using. If you're not using debug, remove it
-
Wilson Wilson almost 4 yearsTry adding minifyEnabled false to your app level build.gradle. And did you add -keep class com.shatsy.** { *; } ?
-
Aman Verma almost 4 yearsIt has been 2 days+ after creating ad unit . and real ads are being showed when i sign the apk in debug mode as written in above reply , and where to add account details
-
Abdullah Khan over 3 yearsI add this line "-keep class com.shatsy.** { *; }" but still ads are not showing in release mode. Ads are working fine in debug mode. Can you also explain the purpose of this line?
-
Arnon Zilca over 2 yearssetting
minifyEnabled false
just for the sake of testing failed for me unless I also addedshrinkResources false