Android + AdMobで「The Google Mobile Ads SDK was initialized incorrectly.」というエラー

AdMobを利用したAndroidのapkをエミュレータ/実機で実行する際におきたエラーです。

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://goo.gl/fQ2neu to add a valid *
* App ID inside the AndroidManifest. Google Ad Manager publishers should *
* follow instructions here: https://goo.gl/h17b6x. *
******************************************************************************

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: https://goo.gl/fQ2neu to add a valid *
* App ID inside the AndroidManifest. Google Ad Manager publishers should *
* follow instructions here: https://goo.gl/h17b6x. *
******************************************************************************

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

原因と解決方法

Google Mobile Ads SDKが不適切だということです。

僕の場合はAdMobのAppID(アプリID)を入力していなかったのが原因でした。

今回はUnityを用いたアプリだったので、Unityエディタ上で設定する方法を書きます。

もしUnityを用いたアプリではない場合は下記リンクの記事を参考に、AndroidManifestを修正してください。
https://ads-developers.googleblog.com/2018/10/announcing-v1700-of-android-google.html

Unityを用いた場合は、エディタ上で設定することができます。

Assets > Google Mobile Ads > Settings…
でインスペクタにGoogleMobileAdsSettingsを開きます。

GoogleAdMobの「Enabled」にチェックを入れ、「AdMob App ID」にAdMobのAppIDを入力します。

この状態でビルドすれば、エミュレータ/実機で実行することができます。

コメント