Reputation: 908
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
Upvotes: 4
Views: 5477
Reputation: 11
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.
Upvotes: 1
Reputation: 4156
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.
Upvotes: 4
Reputation: 3737
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.
Upvotes: 3