Getting 'Invalid Application ID' error when trying to implement AdMob in Android Application

Issue

I have been following google admob vidoes for 3 days, but I’m getting a run time error in the logCat :

Logcat

Process: com.exafmpflle.android.happybirthdayyyy, PID: 19319
java.lang.RuntimeException: Unable to get provider
com.google.android.gms.ads.MobileAdsInitProvider:
java.lang.IllegalStateException:
Invalid application ID. Follow instructions here: to *
* find your app ID.

activitymain

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:background="@drawable/january_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.exafmpflle.android.xxxxxxx.MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/idbuttonfirst"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/idbuttonsecond"
        android:layout_marginStart="79dp"
        android:background="@drawable/ic_iconaphoto"
        android:src="?attr/selectableItemBackground" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-52924220005747xx/xxxxxxxx"  />


</RelativeLayout>
<android.support.design.widget.NavigationView
    android:layout_gravity="start"
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu" />

AndroidMainfest
allso is in my Mainfest

<manifest 
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exafmpflle.android.xxxxxxx"
android:installLocation="auto">

<!-- Include required 2 permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature android:name="android.permission.CALL_PHONE" 
android:required="false" />
<uses-feature android:name="android.permission.READ_PHONE_STATE" 
android:required="false" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

<application
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:installLocation="auto"
    android:icon="@mipmap/ic_launcher_birthdaycake"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

    <!--This meta-data tag is required to use Google Play Services.-->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <!-- Sample AdMob App ID: ca-app-pub-5292422000574799~xxxxxxxx -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="[ca-app-pub-5292422000574799~xxxxxxxxxx"/>

    <activity
        android:name=".SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--Include the AdActivity configChanges and theme. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:theme="@android:style/Theme.Translucent" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:noHistory="false"/>

    <activity
        android:label="@string/about"
        android:name=".About"
        android:screenOrientation="portrait"
        android:noHistory="false" />

    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />

    <!-- [START firebase_service] -->

    <service
        android:name=".FirebaseMessagingService" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <meta-data

    android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorPrimary" />

   <!-- FirebaseMessagingService performs security checks at runtime,
         no need for explicit permissions despite exported="true" -->
    <service

    android:name="com.google.firebase.messaging.FirebaseMessagingService"
        android:exported="true" >
        <intent-filter
            android:priority="-500" >
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
        android:enabled="true"
        android:exported="false" >
    </receiver>
    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.INSTALL_PACKAGES" >
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.google.android.gms.measurement.AppMeasurementService"
        android:enabled="true"
        android:exported="false" />
    <service
    android:name="com.google.android.gms.measurement.AppMeasurementJobService"  
        android:enabled="true"
        android:exported="false"
        android:permission="android.permission.BIND_JOB_SERVICE" />

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.exafmpflle.android.happybirthdayyyy" />
        </intent-filter>
    </receiver>

    <!-- FirebaseInstanceIdService performs security checks at runtime,
         no need for explicit permissions despite exported="true" -->
    <service
        android:name="com.google.firebase.iid.FirebaseInstanceIdService"
        android:exported="true" >
        <intent-filter android:priority="-500" >
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="com.exafmpflle.xxxxxx.xxxxxxxxx.firebaseinitprovider"
        android:exported="false"
        android:initOrder="100" />


</application>

Solution

In your manifest file

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

Change it to :

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

Remove the opening square bracket.
For better practice, define such IDs in string.xml file, instead of using directly.

Answered By – Masoom Badi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published