Artimilion
Artimilion

Reputation: 37

Getting Invalid application ID error when using Test application ID with adMob

I am getting an error when i am trying to implement admob to my app:

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:Invalid application ID

I am using test application ID. Here is my manifest:

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

Gradle:

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

Activity code

MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {
            }
        });

        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        mAdView.loadAd(adRequest);

XML code

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_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"

I do not understand why i am still getting Invalid application ID code. I am using test application ID

Upvotes: 2

Views: 4224

Answers (3)

S. Gissel
S. Gissel

Reputation: 2650

You put your Ad Unit ID in AndroidManifest.xml - which is wrong. You should add your AdMob App ID here.

Ad Unit IDs have this format:

ca-app-pub-3940256099942544/6300978111  //Test ID for a banner

AdMob App IDs have this format:

ca-app-pub-3940256099942544~3347511713  //Test App ID

Upvotes: 9

Gourav
Gourav

Reputation: 2819

You need to use a real ID in both the cases, i.e., the app ID case and also the AdUnit case. If you are in testing, then you may use test ones. But on release, use real IDs from your AdMob dashboard to get real ads when users use your app. Otherwise, the ads won't work.

Upvotes: -1

Artimilion
Artimilion

Reputation: 37

Ok, seems that in manifest i have to put real application ID

Upvotes: 0

Related Questions