1

I am trying to implement Google Admob in Flutter. I have added the required dependencies:

Android Manifest;

Manifest

Added Initialization in the app

Initialization

I have a google-services.json file added to my project which is the same one I have been using for Firestore etc. successfully.

But the app just does not seem to want to start. If I remove the Admob dependency from my pubspec file, the app works so this is definitely to so with the Admob.

I know that the testAppId pulls through the same appid specified in AndroidManifest as this is the google test ad id.

I have not yet implemented any banners, interstitials as yet. i am just trying to initialize first and at least get the app running.

What am I doing wrong?

Waseem Ahmed
  • 379
  • 1
  • 5
  • 17
  • Can you share the crash logs? – Sanjay Sharma Jun 03 '20 at 21:19
  • 1
    @SanjaySharma, don't worry. seems the firebase_admob documentation has to be updated. the position of the meta-data in the android manifest is not correct as per what they indicate. i will post an answer shortly so that everyone is aware of this – Waseem Ahmed Jun 04 '20 at 09:54

1 Answers1

0

So it seems the firebase_admob documentation needs to be updated as it is inaccurate.

The issue is related to the placement of the meta-data tag inside the Android Manifest.

The document indicates to place it within <application>, however it does not indicate what to do if you also have a tag for <activity> :

 <manifest>
    <application>
     <!-- TODO: Replace with your real AdMob app ID -->
     <meta-data
         android:name="com.google.android.gms.ads.APPLICATION_ID"
         android:value="ca-app-pub-################~##########"/>
    </application>
 </manifest>

However, this does not work. I stumbled across the following video(https://www.youtube.com/watch?v=d2aCCIIUebc --> check the 17:20 mark) by chance and the user indicated the same problem and it is solved by moving the tag as following:

 <manifest>
   <application>

     <activity

     </activity>

      <meta-data
       <!-- TODO: Replace with your real AdMob app ID -->
         android:name="com.google.android.gms.ads.APPLICATION_ID"
         android:value="ca-app-pub-################~##########"/>

   </application>
 </manifest>   

Note: the change is to move the Meta-data tag to outside the application tag. This solves the problem and the app does not crash and loads ads as expected.

Waseem Ahmed
  • 379
  • 1
  • 5
  • 17