我将 Android Studio (3.2.1) 及其 sdk 更新到最新版本。之后,需要通过添加以下标签来手动更新清单:
<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
为什么会出现这种情况?我试图研究这个问题,但找不到任何解决方案。这似乎是一个尚未解决的新问题。
发生这种情况是由于更新了 AdMob SDK。现在您需要在清单文件中添加 appID。
<application> . . .
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-################~##########"/>
</application>
您可以从这里获取appID - > Google admob - >选择应用程序 - >应用程序设置 - >应用程序ID。
您可以从这里阅读更多内容广告开发商.
如果您想在放置自己的 ID 之前使用测试广告,请从此处检查 AdMob 测试 ID开发者.google.
希望对你有帮助。谢谢 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)