googleads-mobile-flutter: Google Mobile Ads SDK Developers Privacy • Terms Flutter App crashes when "google_mobile_ads: ^2.3.0" is added into pubspec.yaml

Plugin Version

“google_mobile_ads: ^2.3.0”

So I want to put ads into my app. I followed the instructions from (https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/banner/get-started) and added everything from the docs. When ever I run the app it stops at

Running Gradle task ‘assembleDebug’… √ Built build\app\outputs\flutter-apk\app-debug.apk.

then the app crashes.

Here the pubspec, AndroidManifest and main.dart:

pubspec.yaml:


google_mobile_ads: ^2.3.0

AndroidManifest.xml:

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
and main.dart:

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
await Firebase.initializeApp();

runApp(const MyApp(
backgroundColor: Colors.black,
));
}

The app runs without the

google_mobile_ads: ^2.3.0

Others:


minSdkVersion 23
compileSdkVersion 33
implementation 'com.google.android.gms:play-services-ads:7.5.0'
implementation 'com.android.support:multidex:1.0.3'

I Tried removing each code from the docs starting from

MobileAds.instance.initialize();

and running it each time. Found out that the

google_mobile_ads: ^2.3.0

Was the one causing it.

Im new to this so any help is appreciated

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17

Most upvoted comments

@TiMeJuMp Thank you for reply and solved my issue.

I solve by another way i check library’s example and do same as example it’s works for me and also chnage in pubspec.yaml like this : environment: sdk: ‘>=2.18.6 ❤️.0.0’ to environment: sdk: ‘>=2.12.0 ❤️.0.0’

it’s wworks fine for me.

Hi @XShrimpReal Thanks, now I can see it. But for the issue to be workable, it needs to be reproducible with a completed and minimal reproducible code sample that doesn’t include 3rd party plugins or complex production code. Please provide such a sample.

You may use my above sample code (minimal) combined with other setups (Android side) to elaborate the sample code. Or using google_mobile_ads example could be an option.

Thank you!

Hello again, I have run and tested the sample ads and it worked perfectly. I will try and apply to my code to see if it works. Thanks again

@TiMeJuMp As I see from your sample project, it’s incompleted setup since there is missing APPLICATION_ID on AndroidManifest.xml file.

Please also check guideline from the error message:

E/AndroidRuntime(10157): FATAL EXCEPTION: main
E/AndroidRuntime(10157): Process: com.example.google_ads_sample, PID: 10157
E/AndroidRuntime(10157): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): ******************************************************************************
E/AndroidRuntime(10157): * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
E/AndroidRuntime(10157): * should follow the instructions here:                                       *
E/AndroidRuntime(10157): * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
E/AndroidRuntime(10157): * to add a valid App ID inside the AndroidManifest.                          *
E/AndroidRuntime(10157): * Google Ad Manager publishers should follow instructions here:              *
E/AndroidRuntime(10157): * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
E/AndroidRuntime(10157): ******************************************************************************
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): 	at android.app.ActivityThread.installProvider(ActivityThread.java:7774)
E/AndroidRuntime(10157): 	at android.app.ActivityThread.installContentProviders(ActivityThread.java:7299)
E/AndroidRuntime(10157): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7207)
E/AndroidRuntime(10157): 	at android.app.ActivityThread.access$1700(ActivityThread.java:287)
E/AndroidRuntime(10157): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
E/AndroidRuntime(10157): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(10157): 	at android.os.Looper.loop(Looper.java:255)
E/AndroidRuntime(10157): 	at android.app.ActivityThread.main(ActivityThread.java:8212)
E/AndroidRuntime(10157): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10157): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
E/AndroidRuntime(10157): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
E/AndroidRuntime(10157): Caused by: java.lang.IllegalStateException: 
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): ******************************************************************************
E/AndroidRuntime(10157): * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
E/AndroidRuntime(10157): * should follow the instructions here:                                       *
E/AndroidRuntime(10157): * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
E/AndroidRuntime(10157): * to add a valid App ID inside the AndroidManifest.                          *
E/AndroidRuntime(10157): * Google Ad Manager publishers should follow instructions here:              *
E/AndroidRuntime(10157): * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
E/AndroidRuntime(10157): ******************************************************************************
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): 
E/AndroidRuntime(10157): 	at com.google.android.gms.ads.internal.client.zzee.attachInfo(com.google.android.gms:play-services-ads-lite@@21.3.0:20)
E/AndroidRuntime(10157): 	at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@21.3.0:1)
E/AndroidRuntime(10157): 	at android.app.ActivityThread.installProvider(ActivityThread.java:7769)
E/AndroidRuntime(10157): 	... 10 more