After updating to Fabric Crashlytics sometimes natives crashes with java.lang.NoClassDefFoundError

316 views Asked by At

After last update of Crashlytics with Fabric native app is crashing some times (Tested on nexus 6 with Android 7.1.1)

What I see in Google Play Console is this.

java.lang.NoClassDefFoundError: 
  at io.fabric.sdk.android.Kit.<init> (Kit.java:45)
  at com.crashlytics.android.answers.Answers.<init> (Answers.java:20)
  at com.crashlytics.android.Crashlytics.<init> (Crashlytics.java:29)
  at funler.com.funler.FunlerApplication.onCreate (FunlerApplication.java:27)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1007)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4344)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:135)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1256)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5017)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:779)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:595)
  at dalvik.system.NativeStart.main (Native Method)

of course at funler.com.funler.FunlerApplication.onCreate (FunlerApplication.java:27)

I have

Fabric.with(this, new Crashlytics());

I found something related to MultiDex.install(this) been the issue, but I don't have that in my code. Also saw something related to dexOptions, not sure what to do.

The big issue is that I cant reproduce it as wanted, trying in device it happens ~1 very 20 times.

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

ext {
        versionSdk = 25

        major = 3
        minor = 2
        patch = 5
}

def generateVersionCode(){

        return ext.versionSdk * 1000000 +
                        ext.major * 10000 +
                        ext.minor * 100 +
                        ext.patch;
}

android {

        compileSdkVersion 25
        buildToolsVersion '25.0.3'
        useLibrary 'org.apache.http.legacy'
        defaultConfig {
                applicationId .
                minSdkVersion 16
                targetSdkVersion 25
                versionCode generateVersionCode()
                versionName "${project.ext.major}.${project.ext.minor}.${project.ext.patch}"
                multiDexEnabled true

                .
        }
        productFlavors {
                .
        }
        buildTypes {
                .
        }
        dexOptions {
                jumboMode = true
        }
}


dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        // You must install or update the Support Repository through the SDK manager to use this dependency.
        compile 'com.android.support:support-core-ui:25.4.0'
        compile 'com.android.support:appcompat-v7:25.4.0'
        compile 'com.android.support:design:25.4.0'
        compile 'com.facebook.android:facebook-android-sdk:4.5.0'
        compile 'com.pnikosis:materialish-progress:1.5'
        compile 'com.nineoldandroids:library:2.4.0'
        compile('com.google.apis:google-api-services-youtube:v3-rev112-1.19.0') {
                exclude(group: 'com.google.code.findbugs', module: 'jsr305')
        }
        compile('com.google.api-client:google-api-client:1.18.0-rc') {
                exclude(module: 'jsr305')
        }
        compile 'io.branch.sdk.android:library:2.+'
        compile 'com.google.android.gms:play-services-gcm:8.1.0'
        compile 'com.mcxiaoke.volley:library:1.0.7'
        compile 'org.xwalk:xwalk_core_library:22.52.561.4'
        compile files('libs/MobileAppTracker-3.9.jar')
        compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
                transitive = true;
        }
        compile 'org.greenrobot:eventbus:3.0.0'
        provided files('amazon-device-messaging-1.0.1.jar')
}

configurations {
        compile.exclude module: 'jsr305'
}

buildscript {
        repositories {
                maven { url 'https://maven.fabric.io/public' }
        }

        dependencies {
                classpath 'io.fabric.tools:gradle:1.+'
        }
}

repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
}

repositories {
        maven {
                url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
        }
}
repositories {
        maven { url 'http://download.crashlytics.com/maven' }
}

configurations.all {
        resolutionStrategy.eachDependency { details ->
                def requested = details.requested
                if (requested.group == 'com.android.support') {
                        if (!requested.name.startsWith("multidex")) {
                                details.useVersion '25.4.0'
                        }
                }
        }
}
...
1

There are 1 answers

0
Zohar On

It might be caused by code minification (obfuscation). If you're using proguard (and the issue occurred on release builds), You might want to check out if some library that you are using requires some proguard rules to be added manually.

Best of luck.