Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

flutter - "The Google Mobile Ads SDK was initialized incorrectly"

This is not a repeat of this post (they updated the wrong file).

Getting the error

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: 
java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

even though I update ..appsrcmainAndroidManifest.xml with

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

I followed several tutorials and posts but always with the same result.

I initialize in my main.dart as

FirebaseAdMob.instance.initialize(appId: "ca-app-pub-1234567890123456~1234567890");

Here's my full error report:

Launching libmain.dart on Android SDK built for x86 in debug mode...
libmain.dart
√ Built buildappoutputsflutter-apkapp-debug.apk.
FATAL EXCEPTION: main
Process: com.dreamalytics.dreamapp, PID: 23404
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: 
java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
    at android.app.ActivityThread.access$1300(ActivityThread.java:219)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalStateException:

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************

    at com.google.android.gms.internal.ads.zzzo.attachInfo(com.google.android.gms:play-services-ads-lite@@19.6.0:31)
    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@19.6.0:3)
    at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
    ... 10 more

flutter doctor -v

[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18362.535], locale en-CA)
? Flutter version 1.22.5 at C:projectsflutter
? Framework revision 7891006299 (4 weeks ago), 2020-12-10 11:54:40 -0800
? Engine revision ae90085a84
? Dart version 2.10.4

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
? Android SDK at C:UsersuttoAppDataLocalAndroidsdk
? Platform android-29, build-tools 29.0.2
? Java binary at: C:Program FilesAndroidAndroid Studiojreinjava
? Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
? All Android licenses accepted.

[!] Android Studio (version 4.1.0)
? Android Studio at C:Program FilesAndroidAndroid Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
? Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
? Android SDK built for x86 (mobile) ? emulator-5554 ? android-x86 ? Android 10 (API 29) (emulator)

Full AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dreamalytics.dreamapp">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="Dreamalytics"
    android:icon="@mipmap/launcher_icon">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/notification_icon" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/deep_purple" />
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true"/>
        <meta-data 
            android:name="com.google.android.gms.ads.APPLICATION_ID" 
            android:value="ca-app-pub-4347201915048498~6120388314"/>
    </activity>
</application>
</manifest>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Turns out I had the tag in the <activity> tag scope within <application> so it wasn't recognized.

So, had this

<manifest>
    <application>
        <activity>
            <meta-data> 
                android:name="com.google.android.gms.ads.APPLICATION_ID" 
                android:value="ca-app-pub-4347201915048498~6120388314"/>
        </activity>
    </application>
</manifest>

When I should have had this

<manifest>
    <application>
        <activity>
        </activity>
        <meta-data 
            android:name="com.google.android.gms.ads.APPLICATION_ID" 
            android:value="ca-app-pub-4347201915048498~6120388314"/>
    </application>
</manifest>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...