15
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidでAdMobの初期化時にクラッシュする

Posted at

はじめに

前回の記事で大見得を切ったからには年末年始中に何か一つアプリを作ろうとしてハマったのでメモを残しておきます。

概要

下記の環境で発生した事象をまとめています。
・ Android Studio 3.2.1
・ Kotlin 1.3.10
・ firebase-ads: 17.1.2

やったこと

https://firebase.google.com/docs/admob/android/quick-start?hl=ja の手順に従って下記を実行。

app/build.gradle

依存関係を追加し、促されるままにアップデート

// implementation 'com.google.firebase:firebase-ads:16.0.1' ←アップデート前

implementation 'com.google.firebase:firebase-ads:17.1.2'

Application.kt

SDKの初期化

Application.kt
MobileAds.initialize(this, ADMOB_APP_ID)

しかしビルドしようとすると下記のエラーメッセージを吐いて落ちる

2019-01-01 17:15:30.332 30306-30306/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.masaibar.sample, PID: 30306
    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:6445)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5987)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5902)
        at android.app.ActivityThread.access$1100(ActivityThread.java:200)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.IllegalStateException: 

対処方法

とりあえずエラーメッセージ記載のURLに従ってAndroidManifest.xmlにmeta-dataを追加したら解決しました。
よく見るとFirebaseのAdMobとはそもそもページが違い、よく読んでみるとAdMobを使いたい人のうちFirebaseは使わない人向けとなっているけど大丈夫なんだろうか…

AndroidManifest.xml
<manifest>
    <application>
           :
          (中略)
           :
           <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ADMOB_APP_ID"/>

    </application>
</manifest>

とか思ってたら英語版のドキュメントにはバッチリ書いてありました。
image.png

おわりに

Googleのお家芸である日本語版マニュアル最新版になっていない案件でした、これに懲りて英語版で見る癖つけていきましょう💪

15
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?