googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
336 stars 275 forks source link

Google Mobile Ads SDK Developers Privacy • Terms Flutter App crashes when "google_mobile_ads: ^2.3.0" is added into pubspec.yaml #736

Closed XShrimpReal closed 1 year ago

XShrimpReal commented 1 year ago

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

huycozy commented 1 year ago

Hi @XShrimpReal Can you share the complete crash output?

I also see you are using Firebase, have you completely installed it via installation document? If so, can you provide a completed and minimal reproducible code sample so that we may verify this? (It will be helpful if you can push the sample code to a GitHub repository so that we may pull and verify it, thanks!)

christian-becker-ta commented 1 year ago

Same issue for me. if i remove the code for google_mobile_ads and remove dependency in pubspec.yaml everything works fine.

google_mobile_ads: ^2.3.0

see here small example, install process runs infinte https://github.com/TiMeJuMp/flutter_google_ads_error

huycozy commented 1 year ago

@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
christian-becker-ta commented 1 year ago

great after adding the appid in the manifest, the app runs again correctly. thank you.

But the error message you show here, i didn't found in my output logs.

XShrimpReal commented 1 year ago

Hello, I kinda forgot about this since i gave up on ads but now im back with the github code: https://github.com/XShrimpReal/BetterNotes.git

XShrimpReal commented 1 year ago

These are the changes i added to my code. When i try to launch the app, it crashes everytime. I even have my firebase connected to my admob acc. All same accs linked but i cant get it to run without crashing

Main.dart

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

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

Manifest.xml

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

pubspec.yaml:

google_mobile_ads: ^2.3.0
huycozy commented 1 year ago

@XShrimpReal I tested with below sample code but can not reproduce the issue:

Sample code (Dart) ```dart import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); MobileAds.instance.initialize(); await Firebase.initializeApp(); runApp(const MyApp( )); } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override State createState() => _MyAppState(); } class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Container(color: Colors.red,), ), ); } } ```

Hello, I kinda forgot about this since i gave up on ads but now im back with the github code: https://github.com/XShrimpReal/BetterNotes.git

It seems you set visibility as private so that I can not see the repository. Please set it as public.

XShrimpReal commented 1 year ago

@XShrimpReal I tested with below sample code but can not reproduce the issue:

Sample code (Dart)

Hello, I kinda forgot about this since i gave up on ads but now im back with the github code: https://github.com/XShrimpReal/BetterNotes.git

It seems you set visibility as private so that I can not see the repository. Please set it as public.

Hello, I just changed the visibility to public

XShrimpReal commented 1 year ago

its located in the master branch

huycozy commented 1 year ago

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!

XShrimpReal commented 1 year ago

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!

Alright. Ill try to make a sample and test the google ads plugin. Thanks for the response

XShrimpReal commented 1 year ago

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

XShrimpReal commented 1 year ago

Another update. I was able to get the test banner ads to work on my app. Thank you again. I wil now try the rewarded type.

Mrugesha811 commented 1 year ago

yes , i have also face like crashing with 2.3.0 and flutter sdk is 3.7.0. when i remove just code of google addmob and remove library from yaml file it's works fin but with this library it's crash my app.

christian-becker-ta commented 1 year ago

yes , i have also face like crashing with 2.3.0 and flutter sdk is 3.7.0. when i remove just code of google addmob and remove library from yaml file it's works fin but with this library it's crash my app.

https://github.com/TiMeJuMp/flutter_google_ads_error/tree/master/google_ads_sample try this sample code if it works out. You probably have to add the ApplicationId in the appmanifest in android folder

github-actions[bot] commented 1 year ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

Mrugesha811 commented 1 year ago

@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 <3.0.0' to environment: sdk: '>=2.12.0 <3.0.0'

it's wworks fine for me.