I am trying to implement Google Admob in Flutter. I have added the required dependencies:
Android Manifest;
Added Initialization in the app
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?
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.