Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix a dalvik.system.BaseDexClassLoader.findClass ClassNotFoundException on Android?

I get a dalvik.system.BaseDexClassLoader.findClass ClassNotFoundException crash report on Google play console. The crash is almost exclusive to Samsung Galaxy 7-9 with OS 8 Oreo, 5% of users. I have a Samsung 7 with Oreo in the office, and I have tried all the devices at the Samsung Remote Test Lab, but I cannot replicate the crash. The crash occurs with or without multidex, I have cleared caches, rebuilt and disabled Instant Run. This problem did not occur until I changed targetSdkVersion to 26. Android Studio, gradle build. Since I cannot replicate the crash, I am reduced to making random changes and uploading to the playstore, then checking the crash reports the next day. Thanks in advance!

Samsung Galaxy S9 (starqltesq), Android 8.0
Report 1

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3374)
  at android.app.ActivityThread.-wrap18 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1780)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Caused by: java.lang.ClassNotFoundException: 
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:93)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3369)

Edited app build .gradle:

android {
    compileSdkVersion 27
    buildToolsVersion '25.0.0'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 26
        multiDexEnabled false
    }
    buildTypes {
        release {
            minifyEnabled false
            if (is_main_app) {
                signingConfig signingConfigs.releaseMain
            } else if (is_simutrader_app) {
                signingConfig signingConfigs.releaseSimutrader
            } else {
                signingConfig signingConfigs.releaseTsx
            }
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dependencies {
    androidTestCompile 'junit:junit:4.12'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':volley')
    compile files('libs/gson-2.3.1.jar')
    compile 'io.branch.sdk.android:library:1.+'
    compile files('libs/mpandroidchartlibrary-2-0-9.jar')
    compile 'com.thebluealliance:spectrum:0.5.0'
    compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
    compile 'com.android.support:appcompat-v7:27.1.0'
    compile 'com.android.support:cardview-v7:27.1.0'
    compile 'com.android.support:design:27.1.0'
    compile 'com.android.support:support-v4:27.1.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.google.android.gms:play-services-gcm:11.+'
    compile 'com.google.android.gms:play-services-analytics:11.+'

    compile 'com.google.firebase:firebase-core:11.+'

    compile 'com.urbanairship.android:urbanairship-sdk:8.7.+'
    // compile 'com.android.support:multidex:1.0.3'

}

apply plugin: 'com.google.gms.google-services'
like image 739
user2680414 Avatar asked Jul 14 '26 08:07

user2680414


2 Answers

I have the solution. I added NewRelic to the build and got this:

CRASH TYPE SUMMARY
LOCATION
BaseDexClassLoader.java line 93 in dalvik.system.BaseDexClassLoader.findClass()
EXCEPTION
java.lang.ClassNotFoundException
MESSAGE
Didn't find class "com.urbanairship.push.GCMPushReceiver" on path: DexPathList[[zip file "/data/app/com.****.android-tUaBU1BXe0VaMGy9WlkUGA==/base.apk"],nativeLibraryDirectories=[/data/app/com.*****.android-tUaBU1BXe0VaMGy9WlkUGA==/lib/arm64, /system/lib64, /system/vendor/lib64]]

Which tells me that com.urbanairship.push.GCMPushReceiver was the culprit. So a tracking library is a usefull problem solving tool. Thanks for the replies!

p.s. As a general observation, a lot of the SO "have you tried changing ...insert random setting...? That is guaranteed to work!" replies are largely not terribly helpful.

like image 164
user2680414 Avatar answered Jul 15 '26 22:07

user2680414


You can follow android developers page's instruction: https://developer.android.com/studio/build/multidex.html

Edit app.gradle file with this code,

defaultConfig {
...
minSdkVersion // your version
targetSdkVersion // your version 
...

// Enabling multidex support.
 multiDexEnabled true
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

I think this will be helpful.

like image 31
Sana Avatar answered Jul 15 '26 21:07

Sana