【发布时间】:2019-03-18 02:58:39
【问题描述】:
我将我的 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
有人可以告诉我为什么会发生这种情况或帮助我解决它吗?我试图用谷歌搜索这个问题,但没有解决方案。这似乎是一个新的尚未解决的问题。非常感谢。
【问题讨论】:
-
你把元数据标签具体放在哪里了?
-
我编辑了问题并添加了清单数据。现在你应该可以看到我把元数据标签放在哪里了。很抱歉,但我不想分享应用 ID 和广告 ID,这就是我更换或更改它们的原因。谢谢你的帮助兄弟!
-
我也遇到了同样的问题,但是在我的应用中我没有包含广告,我应该添加元数据部分吗?如果是这样,我可以从哪里获得 appID?我没有找到“Google addmob”的位置。
-
请注意:元数据标签必须以不同的方式处理,具体取决于您使用什么来投放广告。使用 AdMod 时使用:developers.google.com/admob/android/… 使用 Google Ad-Manager 时使用:developers.google.com/ad-manager/mobile-ads-sdk/android/…