81

I update my Android Studio (3.2.1) and its sdk to the latest version. After that it required a manual update for Manifest by adding these tags:

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

whereby instead the app ID I put the real id of my app. The value has also been changed to the right Ad Unit id as shown here https://developers.google.com/admob/android/quick-start. I also called this function in the MainActivity.kt:

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

However, the problem could not be solved. It still prints as follows:

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

Why does this happen? I tried to research the issue, but I can't find any solutions. It seems to be an a new still unsolved issue.

7
  • Where exactly did you put the meta data tag? Commented Oct 12, 2018 at 21:05
  • I edited the question and added the manifest data. Now you should be able to see where I put the meta data tag. I am sorry, but I don't want to share app id and ads id, that's why I replaced or changed them. Thank for your help bro! Commented Oct 12, 2018 at 21:34
  • 1
    Follow this answer stackoverflow.com/questions/53294162/… Commented Nov 23, 2018 at 8:40
  • 4
    I am facing same problem, but in my app I didn't include ads, should I add the meta-data part? if so, where can I get the appID from? I didn't get where "Google addmob" could be found.
    – coder
    Commented Jan 7, 2019 at 13:12
  • 1
    @coder go to manifest -> Merged Manifest , you can find these tags, delete all of them : . . <provider android:name="com.google.android.gms.ads.MobileAdsInitProvider" tools:node="remove" /> <service android:name="com.google.android.gms.ads.AdService" tools:node="remove" /> <meta-data android:name="com.google.android.gms.version" tools:node="remove" />
    – Ali Salehi
    Commented Feb 1, 2022 at 11:59

25 Answers 25

93

This happened due to updated AdMob SDK. Now you need to add appID in your manifest file.

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

You can get appID from here -->Google addmob -->Select app --> App Settings --> App ID.

You can read more from here ads-developers.

If you want to use test ads before putting your own id check the AdMob test ids from here developers.google.

Hope this will help you. Thanks :)

5
  • 3
    I found the problem, I used the wrong ID (ID for AdUnit) and that's why it did not work. Many thanks! Commented Oct 13, 2018 at 18:56
  • 1
    It worked for me, and just to add a side note, you may want to use test ads before putting your own id, where it says "ca-app-pub-################~##########" check the AdMob test ids at : developers.google.com/admob/android/test-ads
    – user6153372
    Commented Dec 27, 2018 at 18:03
  • @SaveenDhiman I am facing same problem, but in my app I didn't include ads, should I add the meta-data part? if so, where can I get the appID from? I didn't get where "Google addmob" could be found.
    – coder
    Commented Jan 8, 2019 at 6:39
  • 1
    Hi @coder Can i know which google service(com.google.android.gms:play-services) you are using in your application?
    – Saveen
    Commented Jan 8, 2019 at 10:58
  • 2
    @SaveenDhiman I just noticed I had com.google.android.gms:play-services-ads in my grade I commented it out and the error is not showing anymore, thank you.
    – coder
    Commented Jan 9, 2019 at 5:35
70

Google gave update for the Google ads so if you update your Admob library in gradle then you need to add this in your manifest.

<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>
4
  • 2
    How can I avoid this if am testing using androidTests
    – vizsatiz
    Commented Apr 3, 2020 at 7:10
  • 2
    I've spent a lot of time finding right test AppId. Just add this official test id: ca-app-pub-3940256099942544~3347511713 source
    – Shpand
    Commented Apr 16, 2020 at 8:35
  • 1
    Also, be sure you are modifying "main\AndroidManifest.xml" and not "profile\AndroidManifest.xml" or "debug\AndroidManifest.xml"
    – Sludge
    Commented May 17, 2020 at 16:43
  • The format of admob_app_id is changed like as mentioned in the android:value answer.
    – Ravi Yadav
    Commented Aug 11, 2020 at 12:34
30

Add In Your Manifest File

<meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true" />
1
  • why do add this?
    – MBH
    Commented Jul 15, 2020 at 8:36
17

Don't get confused with APPLICATION_ID. You should not replace it with your application ID for ex. com.example.myapp. Just keep it as it is.

<application>
...
      <meta-data 
           android:name="com.google.android.gms.ads.APPLICATION_ID" 
           android:value="ca-app-pub-################~##########"/>
...
</application>
2
  • thanks man, this was my issue. I think they should have made this point clear in their guide Commented Apr 8, 2022 at 16:21
  • Oh man, I wasted a lot of time because of this. Thanks a lot! Commented Feb 19 at 19:46
12

I have already added <meta-data...../> but the error didn't resolve. The solution is to put <meta-data.../> at last of other meta-data in your androidManifest.xml file present in android -> app -> src -> main . Like this:

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

The solution is to put the meta data lines at Last (means below all other meta-data present in your android manifest file but just before closing application tag).

4
  • 4
    Worked for me after I had put in 4 hours into it. Really underrated answer. Commented Dec 27, 2020 at 11:52
  • 1
    Now I got it. Thank for your answer.
    – Wai Yan
    Commented May 31, 2021 at 11:34
  • 2
    that was it omg... put it at the very bottom before closing </application> tag
    – giorgio79
    Commented Oct 19, 2021 at 17:45
  • 2
    Worked for me! Under rated...
    – Tomas Ward
    Commented Oct 26, 2021 at 19:32
8

Important: This step is required as of Google Mobile Ads SDK version 17.0.0. Failure to add this tag results in a crash with the message: The Google Mobile Ads SDK was initialized incorrectly.

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>
7

Google Mobile Ads SDK v17.0.0 for Android has just been released, and it comes with these important changes.

Required AndroidManifest.xml changes

Starting in version 17.0.0, if you are an AdMob publisher you are now required to add your AdMob app ID in your AndroidManifest.xml file. Once you find your AdMob app ID in the AdMob UI, add it to your manifest adding the following tag:

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

Failure to add this tag will result in the app crashing at app launch with a message starting with The Google Mobile Ads SDK was initialized incorrectly.

What if I'm using Google Ad Manager instead of AdMob?

Publishers using Google Ad Manager will need to declare themselves as an Ad Manager app with a different tag to avoid the same crash:

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

See the link for more details.

5

With the new Admob library we have to initialize and load Ad in the onCreate() method and add the App ID inside AndroidManifest file like mentioned in the other answers. But don't put the Ad ID in AndroidManifest by confusing it with the App ID which was the mistake that I was doing.

Ex App ID:  ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx 

Ex Ad ID:   ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx 
0
4

In my case, I have accidentally put the meta-data tag inside activity tag like below,

    <manifest>
      <application>
         <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
             <meta-data
               android:name="com.google.android.gms.ads.APPLICATION_ID"
               android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
       </activity>
    </application>
</manifest>

please make sure to add the mata tag outside the activity tag

 <manifest>
  <application>
     <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
   </activity>
   <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
4

As for me I was following the instructions from the official google website and Enabling test adds but it turned out there is a wrong character causing the exception. The Id is shown as ca-app-pub-3940256099942544/6300978111 but what's working is ca-app-pub-3940256099942544~6300978111 notice the difference. / and ~

 <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="@string/testId"/>

strings.xml

    <string name="testId">ca-app-pub-3940256099942544~6300978111</string>
1
  • This fixed it for me. Weirdly, the erroneous / in the id worked fine for my Mac dev environment/emulator but I was seeing this problem on my Linux dev environment only.
    – John Dunne
    Commented Nov 22, 2023 at 17:00
3

If you haven't published your app, try the following

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

Make sure you don't have your meta-data tag inside activity...been there, done that.

2

I think the name should be "APPLICATION_ID" not "APP_ID"

2
  • 1
    Sure! In addition, I already tried to replace it with the real app id defined in build.gradle under applicationId. No success, the app still crashes.... Commented Oct 13, 2018 at 15:30
  • do you mean to replace "APPLICATION_ID" with which id? the App_id? because it crashes when i'm setting it this way.
    – eyalix
    Commented Nov 20, 2019 at 13:51
2

Note: if you're storing the ID on strings.xml file please do it right like that

in Manifest.xml:

<application>
           <!-- some code here -->
            <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="@string/admobID" />
           <!-- some code here -->
 </application>

in strings.xml:

 <!-- change it with your ID -->
       <string name="admobID" translatable="false">ca-app-pub- 
                       xxxxxxxxx~xxxxxxxxx</string>

Exemple: if you forget to add @ to string/admobID it will cause the same Exception

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

this should be outside of activity but inside manifest and application

<manifest>
    <application>
        <activity>
              It shouldn't be here
         </<activity>            


        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>
1
  • Thanks, If haven't noticed the meta-data be inside <activity>
    – Infomaster
    Commented Sep 30, 2023 at 9:16
2

I was desperate for 3 hours to find the solution and I find out (to google_mobile_ads 2.3.0 in my case) is necessary to put the next configuration.

In AndroidManifest.xml

   <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713"
        />

Outside from tag Activity and below add the next line, like the code example:

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

In Unity3D starting V3.18 & Ad SDK V 7.45.0, you need to setup these data @ Menu : Assets > Google Mobile Ads > Settings & it will automatically write these data in manifest file.

Adding APPLICATION_ID & AD_MANAGER_APP into manifest file directly which is already given in other answers was still crashing for me.

0

For those who are getting this error in Xamarin Forms Cross Platform app, the error

Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException`

it might be due to version of Xamarin.GooglePlayServices.Ads installed. When I used Version 71.1720.0 I was getting this error. Hence I uninstalled this version and restored it to Version 60.1142.1 and it worked without crashing.

For tutorial please refer to this Youtube Video

2
  • 1
    Going back to an older version is not the real solution. According to some issues in the Xamarin.GooglePlayServices Github repo, a temporary workaround is to add the Xamarin.Android.ManifestMerger (preview as of 2020/15/01).
    – MSicc
    Commented Jan 15, 2020 at 13:33
  • I have exactly this issue with XF. @MSicc, could you give please more information, links? Thanks!
    – Zoli
    Commented Apr 3, 2020 at 9:32
0

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider"

If you are getting the error above and while searching you've come up here, it may not be because you forgot to insert adMob meta data inside your manifest. I have faced this issue and the solution is implementing the MultiDex inside your application.

Here is the Google instructions : link

0

Make sure you check following steps.

1. Project level Gradle has google() added in all projects.

allprojects {
    repositories {
        google()
    }
}

2. App level Gradle has following dependency added mentioned same as sample below:

**implementation 'com.google.android.gms:play-services-ads:19.3.0'**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:19.3.0'
}

3. Update App-ID in AndroidManifest.xml mentioned in <meta-data>. Replace your App-ID in android:value

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

4. adView is added to the layout. Make sure you added ads:adUnitId not App-ID both are different.

I was getting error because I was confused between two. App-ID has "/" and adUnitId has "~". For testing purpose use "ca-app-pub-3940256099942544/6300978111" as adUnitId otherwise your account will get suspended.

When you are ready to publish you can add your real id and publish.

<com.google.android.gms.ads.AdView
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true"
      ads:adSize="BANNER"
      ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
  </com.google.android.gms.ads.AdView>

Check all 4 steps and you will be able to resolve this error.

0

Make sure to check well because it should be App ID not ADd ID in <meta-data ..../> manifest file.

App ID: ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx 
Ad ID: ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx 
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Dec 20, 2021 at 20:01
0

Replacing the slash (/) in the ID with tilde (~) fixed it for me. But I've got no idea why they give you the id with slash on the Google AdMob web site, but then expect you to change it to a tilde... Bizarre.

0

Go to your admob website > Select App > App Setting > Copy AdMob Id

Note : Admob Id is different from your Ad Unit Id

Then add meta tag in your manifest

 <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-XXXXXXXXXXXXXXXXXXXXX"/>
1
  • Dude, you see there are already answers, don't you? Commented Dec 28, 2022 at 6:54
0

Application Id to be added in manifest has ~ in it and adUnitId to be added in the code has / in it. Using same thing in both the places is one cause for this error.

0

for old ads SDK for example :
implementation 'com.google.android.gms:play-services-ads:21.0.0'
you should write something like this :

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

For new ads SDK
for example : implementation 'com.google.android.gms:play-services-ads:23.3.0'
you should write :

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

The difference are : You should write APPLICATION_ID as a symbol (not real numbers in the new SDK)

Not the answer you're looking for? Browse other questions tagged or ask your own question.