4

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

Aman Verma
  • 818
  • 5
  • 17

3 Answers3

4

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.

Hadi Mir
  • 4,497
  • 2
  • 29
  • 31
Wahdat Jan
  • 3,988
  • 3
  • 21
  • 46
  • It 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 – Aman Verma May 01 '20 at 09:24
3

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.

Wilson Wilson
  • 3,296
  • 18
  • 50
1

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.