Fdx Regan
Fdx Regan

Reputation: 3

Android 8.1 Unable to get provider com.google.android.gms.ads.MobileAds!!! apk crash

My Android Studio version 3.4.1, I am trying to add MobileAds code into my project built with sdk 28, but getting crash report. I don't know why????

I have checked all the similar posts but some of are outdated and unfortunately could not get any solution

My Android Manifest is

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

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-3940256099942544/6300978111"/>
        <activity
    android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:screenOrientation="portrait" />

MainActivity Layout

    <com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_weight="1"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

App build.gradle

   android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
buildTypes {
release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.txt'
}
}
repositories {
jcenter()
mavenCentral()  // GPUImage for Android
}
dexOptions {
javaMaxHeapSize "4g"
}
productFlavors {
}
} 
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/acra-4.5.0.jar')
implementation files('libs/ormlite-android-4.43.jar')
implementation files('libs/ormlite-core-4.43.jar')
// If you want to use the GPU Filters
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
 implementation 'com.google.firebase:firebase-ads:17.2.1'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'com.onesignal:OneSignal:3.10.9'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.google.android.gms:play-services-ads:17.2.1'
implementation 'com.google.android.gms:play-services-maps:+'

}
apply plugin: 'com.google.gms.google-services'

HomeActivity.java

    @Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_new);
MobileAds.initialize(this, "ca-app-pub-3940256099942544/6300978111");

AdView mAdView = (AdView) findViewById(R.id.adView);
try{

    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    if (admov_status.equalsIgnoreCase("true")){
        mAdView.setVisibility(View.VISIBLE);
    }else if(admov_status.equalsIgnoreCase("false")) {
        mAdView.setVisibility(View.GONE);
    }
}catch (RuntimeException e){
    mAdView.setVisibility(View.GONE);
}
}

But still the ERROR is running. Error logcat details here

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

******************************************************************************
* Invalid application ID. Follow instructions here: Link to *
* find your app ID.                                                          *
******************************************************************************


    at android.app.ActivityThread.installProvider(ActivityThread.java:6242)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: java.lang.IllegalStateException: 

******************************************************************************
* Invalid application ID. Follow instructions here: Link to *
* find your app ID.                                                          *
******************************************************************************


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

Can anyone help me to figure out the problem please.

Upvotes: 0

Views: 4986

Answers (4)

razi
razi

Reputation: 97

I had the same problem. After doing the above recommendation I also added

repositories {
    google()
    jcenter()
    mavenCentral()  // GPUImage for Android
}

in the build.gradle file and then the problem was resolved. Also, make sure to use application Id in the manifest and not UnitId.

Upvotes: 0

Merthan Erdem
Merthan Erdem

Reputation: 6068

Not the answer for you, but might help others:

Dynamic Feature modules cause problems when you don't include the dependency in the base build.gradle (app) file too (only dynamic manifest isn't enough).

Upvotes: 0

Janmenjaya
Janmenjaya

Reputation: 4163

I was facing the same issue, struggling to understand the above answer, then I tried few hit & try and it worked, later I understood the above answer. So I am putting my observation & experience with graphical representation, to make it easy to integrate

Steps to follow:

  • Create a AdMob Account If you don't have (https://apps.admob.com/signup/)
  • Create an App going to the left Panel & providing required details asked there (Refer Image - 1)

Image - 1

enter image description here

  • Once asked details are given, you will see a screen like given in Image - 2

Image - 2

enter image description here

  • Then you can go for adding "AD Unit" or click "Done". (If you click Done You will be redirected to AppOverview page, there you can Add "AD Unit").
  • Now Click on App -> View All Apps (Again Refer Image -1, to see the option)
  • Then You will be redirected to a page where all Apps info will be shown (Refer Image - 3)

Image - 3

enter image description here

  • Click on the AppId shown there, Thats your App Id. Copy that and Paste in the Manifest file in the value string as shown below, you can also refer the Image -4

Image -4

enter image description here

           <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-8623492450664484~4654380864">
  • Then go to your Activity.xml file (Where you added the Ad Mob banner), and add the "Ad Unit Id"as shown below

            <com.google.android.gms.ads.AdView
             android:id="@+id/adView"
             android:layout_width="416dp"
             android:layout_height="52dp"
             android:layout_alignParentBottom="true"
             android:layout_centerHorizontal="true"
             ads:adSize="BANNER"
             ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
             tools:ignore="MissingConstraints" />
    

If you want to test, use "AdUnitId" as mentioned below (suggested by AdMob developer document)

ca-app-pub-3940256099942544/6300978111

Then add the following two line in your corresponding Activity (Kotlin File)

    val adRequest = AdRequest.Builder().build()
    mAdView?.loadAd(adRequest)

Now run the App, you will see the Ad Banner. Hope this will be helpful

Upvotes: 0

Anjana
Anjana

Reputation: 933

There are 2 ad ids in Admob.

1). appID

2). adUnitID

For an app whatever the your ad type you use, the appID is same. But the the adUnitID differs for the each ad type you use. For example, you can have both banner ads and interstitial ads in the App. For both of those ad types appID is same, but the adUnitID differs.

As per your code you have used the same ID everywhere, which is not correct. You need to use appID, adUnitID in appropriate places. In layout xml, where you declare the ad unit it should have adUnitID and other places appID.

Manifest.xml

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value=**appID**/>

MainActivity Layout

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_weight="1"
ads:adSize="SMART_BANNER"
ads:adUnitId=**adUnitID**>

HomeActivity.java

MobileAds.initialize(this, **appID**);

So in your case, it seems that you have used adUnitID for the the places you should have used appID. That's probably why it throws the error as in

******************************************************************************
* Invalid application ID. Follow instructions here: Link to *
* find your app ID.                                                          *
******************************************************************************

Refer this link on how to find out appID and adUnitID for your adMob

Upvotes: 2

Related Questions