Search code examples
androidadmobbanner-ads

Admob shows Test ads with test adUnitId but for real adUnitId app crashed


When I test my app with test(ca-app-pub-3940256099942544/6300978111) adUnitId it shows ads but when I replace test adUnitId with real one app get crashed.

Error Log:

E/AndroidRuntime: FATAL EXCEPTION: Thread-13
Process: biz.coolpage.aashish.app, PID: 13682
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
    at jp.b(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):3)
    at jo.a(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):3)
    at jq.a(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):19)
    at com.google.android.gms.ads.internal.util.aq.a(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):15)
    at iu.a(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):19)
    at iu.run(:com.google.android.gms.dynamite_adsdynamite@14799084@14.7.99 (100700-223214910):8)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000f/AdsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000f/AdsDynamite.apk!/lib/x86, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader@14799084@14.7.99 (100700-223214910):4)

Inside LinearLayout in xml file:

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

Inside the OnCreate method:

    MobileAds.initialize(this, getString(R.string.AdMob_app_id));
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

Solution

  • After wasting so many hours finally I got the root cause of this crash.

    When you add an app in your AdMob account then by default ads based on location has ON. So, if your app doesn't have location permission then the app crashed.

    Solution:--

    Either you will turn OFF ads based on the location from your AdMob account

    OR

    you can ask your users to provide access to their locations.