Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermittent java.lang.NoClassDefFoundError at runtime from AdMob

A few of my users are crashing with an error.. the phones with this crash are Google Pixels running Android 9. However, not all Pixels crash with this configuration. The two devices that reported the crash were Google Pixel 2 (walleye) on Android 9 and Pixel XL (marlin) on Android 9. We have users with the same device and Android version that do not have the error and we have not been able to reproduce the error in an emulator.

Here is the stack trace reported:

java.lang.NoClassDefFoundError: 
  at jq.b (jq.java:3)
  at jp.a (jp.java:3)
  at jr.a (jr.java:19)
  at com.google.android.gms.ads.internal.util.ap.a (ap.java:15)
  at iv.a (iv.java:19)
  at iv.run (iv.java:8)
Caused by: java.lang.ClassNotFoundException: 
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:134)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
  at ac.loadClass (ac.java:4)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
  at jq.b (jq.java:3)
  at jp.a (jp.java:3)
  at jr.a (jr.java:19)
  at com.google.android.gms.ads.internal.util.ap.a (ap.java:15)
  at iv.a (iv.java:19)
  at iv.run (iv.java:8)

Here is my build.gradle for my common library:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28

    libraryVariants.all { variant ->
        variant.outputs.all {
            def version = variant.properties.get("versionName")
            def projectName = name
            def formattedDate = new Date().format('yyyy-MM-dd-HHmm')
            outputFileName = "${projectName}${version}-${formattedDate}.apk"
        }
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 6
        versionName "3.0.1"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    dependencies {
        implementation 'com.google.android.gms:play-services-ads:15.0.1'
    }
}

Here is my build.gradle for my application:

apply plugin: 'com.android.application'


android {

    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 9
        versionName "2.6.2"
        testApplicationId "com.myapp"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        signingConfig signingConfigs.appkey
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            zipAlignEnabled true
            android.applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def relativeRootDir = output.packageApplication.outputDirectory.toPath()
                            .relativize(rootDir.toPath()).toFile()
                    def finalVersionCode = versionCode
                    output.versionCodeOverride = finalVersionCode
                    outputFileName = new File(
                            "$relativeRootDir/release",
                            outputFileName.replace(".apk", "-${finalVersionCode}.apk"))
                }
            }
            debuggable true
            jniDebuggable true
        }
        debug {
        }
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '28.0.3'
    productFlavors {
    }
}

dependencies {
    implementation project(':common')
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
}
like image 525
Ebry Dobby Avatar asked Nov 07 '22 23:11

Ebry Dobby


1 Answers

As stated in this answer, it appears there's a temporary workaround while we wait for this to be officially fixed from Google. Maps library is also affected.

Just put this tag into the Manifest file:

<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />

I tried it and it appears to be working.

like image 182
Antonio Papalillo Avatar answered Nov 15 '22 11:11

Antonio Papalillo