在某些设备上获取java.lang.NoClassDefFoundError以获取admob插页式广告

时间:2019-03-22 15:36:54

标签: gradle admob

Play商店报告在某些设备上最新的AdMob崩溃:

java.lang.NoClassDefFoundError: 
  at jq.b (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):3)
  at jp.a (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):3)
  at jr.a (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):19)
  at com.google.android.gms.ads.internal.util.ar.a (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):15)
  at iu.a (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):20)
  at iu.run (com.google.android.gms.dynamite_adsdynamite@15090081@15.0.90 (100400-231259764):8)
Caused by: java.lang.ClassNotFoundException: 
  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@15090081@15.0.90 (100400-231259764):4)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)

我已经升级了gradle文件,以使用最新的targetSdkVersion 28和最新的AdMob SDK 17.2.0。但是我在使用不同版本的com.android.support库时遇到了冲突问题。我可以通过“强制” 28.0.0版中的com.android.support库来正确编译。也许这是引起问题的原因?我没有做任何花哨的事情,仅包括admob,facebook,firebase等……对于较旧的targetSdkVersion,相同的应用程序代码也不会崩溃。

我还注意到有可能在使用不同lib实现'com.google.firebase:firebase-ads:17.2.0'和不同类并在清单中查询不同数据的firebase上添加广告。

这是我的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 373
        versionName "4.0.6"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "tier"
    productFlavors {
       playStoreFree {
            ...
            dimension "tier"
        }

repositories {
    mavenCentral()
    maven {
        url "https://maven.google.com"
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':SliderPreference')
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.android.gms:play-services-ads:17.2.0'
    implementation 'com.google.android.gms:play-services-analytics:16.0.8'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    implementation 'com.facebook.android:facebook-android-sdk:4.31.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
}

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

我有清单

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

主要活动:

InterstitialAd mInterstitialAd;

@Override
protected void onPostCreate(Bundle savedInstanceState) {
MobileAds.initialize(context, BuildConfig.AD_APP_ID);
        MobileAds.setAppMuted(true);

        mInterstitialAd = new InterstitialAd (this);
        mInterstitialAd.setAdUnitId(BuildConfig.AD_UNIT_ID);

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdFailedToLoad(int errorCode) {
                Log.d("AD", "onAdFailedToLoad: "+String.valueOf(errorCode));
                super.onAdFailedToLoad(errorCode);
            }

            @Override
            public void onAdLoaded() {
                Log.d("AD", "onAdLoaded: ");
                super.onAdLoaded();
            }

            @Override
            public void onAdClosed() {
                    requestNewInterstitial();
            }
        });
        requestNewInterstitial();
    }
}


private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder().build();
        mInterstitialAd.loadAd(adRequest);
}       

1 个答案:

答案 0 :(得分:2)

来自Admob的答案

感谢您与我们联系。我们的团队已解决此问题。该修补程序应在以后的SDK版本中可用。请关注我们的发行历史页面以获取更多更新。