无法获取提供者com.google.android.gms.ads.MobileAdsInitProvider:java.lang.IllegalStateException:为什么?

问题描述 投票:28回答:5

我将我的Android Studio(3.2.1)及其sdk更新到最新版本。之后,它需要通过添加这些标记手动更新Manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@drawable/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning">

    <meta-data
        android:name="com.google.android.gms.ads.APP_ID"
        android:value="ca-app-pub-#############"/>

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".NewActivity" />
    <activity android:name=".PreviewActivity" />
    <activity android:name=".EditActivity" />
    <activity
        android:name=".preferencesdata.AboutActivity"
        android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" />
    <activity android:name=".preferencesdata.SettingsActivity"
        android:label="@string/settings">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>
</application>

相反,应用程序ID我把我的应用程序的真实ID。该值也已更改为正确的广告单元ID,如此处所示https://developers.google.com/admob/android/quick-start。我还在MainActivity.kt中调用了这个函数:

MobileAds.initialize(this, resources.getString(R.string.banner_ad_unit_id)) 

但是,问题无法解决。它仍然打印如下:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.easyapps.cryptnote, PID: 3991
    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 LINK to add a valid  *
    * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
    * follow instructions here: LINK.                           *
    ******************************************************************************


        at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
        at android.app.ActivityThread.-wrap1(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalStateException: 

    ******************************************************************************
    * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
    * should follow the instructions here: LINK to add a valid  *
    * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
    * follow instructions here: LINK.                           *
    ******************************************************************************


        at com.google.android.gms.internal.ads.zzmn.attachInfo(Unknown Source)
        at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(Unknown Source)
        at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
            ... 10 more

有人可以告诉我为什么会这样或者帮助我解决它?我试图谷歌这个问题,但没有解决方案。这似乎是一个尚未解决的新问题。提前谢谢了。

android kotlin sdk ads
5个回答
20
投票

Google为Google广告提供了更新,因此如果您在Gradle中更新Admob库,则需要在清单中添加此广告。

<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>

57
投票

这是因为更新的AdMob SDK。现在,您需要在清单文件中添加appID。

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

您可以从此处获取应用ID - > Google admob - >选择应用 - >应用设置 - >应用ID。

你可以在这里阅读更多ads-developers

如果您想在使用自己的ID之前使用测试广告,请点击此处developers.google查看AdMob测试ID。

希望这会帮助你。谢谢 :)


15
投票

添加您的清单文件

<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />


1
投票

我认为名称应该是“APPLICATION_ID”而不是“APP_ID”


0
投票

谷歌移动广告SDK v17.0.0 for Android刚刚发布,它带来了这些重要的变化。

必需的AndroidManifest.xml更改

从版本17.0.0开始,如果您是AdMob发布商,则需要在AndroidManifest.xml文件中添加AdMob应用ID。在AdMob用户界面中找到AdMob应用ID后,将其添加到您的清单中,添加以下标记:

<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>

如果未能添加此标记,则会导致应用在应用启动时崩溃,并显示以The Google Mobile Ads SDK was initialized incorrectly.开头的消息

如果我使用的是Google广告管理系统而不是AdMob,该怎么办?

使用Google广告管理系统的发布商需要将自己声明为具有不同标记的广告管理系统应用,以避免同样的崩溃:

<manifest>
    <application>
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true"/>
    </application>
</manifest>

有关详细信息,请参阅link

© www.soinside.com 2019 - 2024. All rights reserved.