Fabric/Crashlytics NoClassDefFoundError only on certain devices

前端 未结 6 1201
醉酒成梦
醉酒成梦 2020-12-20 16:04

I\'m seeing a crash in Google Play related to Fabric/Crashlytics. This happened after I updated from normal Crashlytics to the new Fabric Crashlytics. I can only reproduce i

相关标签:
6条回答
  • 2020-12-20 16:42

    please build this: compile 'com.android.support:multidex:1.0.1'

    and add this method in your application class :

               protected void attachBaseContext(Context base) {
                   super.attachBaseContext(base);
                   MultiDex.install(this);
                }
    
    0 讨论(0)
  • 2020-12-20 17:03

    If you're using MultiDex correctly and still running into this error, it may be because you are using Proguard and MultiDex doesn't know which classes to keep.

    So be sure to "sync" your MultiDex keep file with your Proguard .pro file.

    Example:

    buildTypes {
       // other stuff...
    
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ext.enableCrashlytics = true
    
            //
            // IMPORTANT PART:
            //
            // tell your MultiDex to keep the classes you defined in your Proguard .pro file.
            multiDexKeepProguard file('proguard-rules.pro')
        }
    }
    

    By doing this, you don't need to manually specify a multidex.keep file!

    More info on multiDexKeepProguard here, and the full developer docs from Google.

    0 讨论(0)
  • 2020-12-20 17:03

    I'm trying to remedy this bug by updating Crashlytics to 2.9.1. According to https://docs.fabric.io/android/changelog.html#february-28-2018 :

    Fixed bug causing Firebase Crashlytics to fail to start when Firebase Core is not explicitly included as a dependency.

    My build.gradle now reads:

    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true;
    }
    

    EDIT: didn't help. On Android 4.x Crashlytics crashes. What irony.

    0 讨论(0)
  • 2020-12-20 17:06

    First check Fabric SDK is add or not then after If you got this error check below files.

    01-26 12:15:46.186  32094-32094/com.example.android I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
    01-26 12:15:46.186  32094-32094/com.example.android I/SELinux﹕ SELinux: VERIFYSIG  File Open Unsuccessful:
    01-26 12:15:46.186  32094-32094/com.example.android I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig or checkHash fails. priority version is VE=SEPF_GT-I9500_4.4.2_0018
    01-26 12:15:46.186  32094-32094/com.example.android I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
    01-26 12:15:46.191  32094-32094/com.example.android E/dalvikvm﹕ >>>>> Normal User
    01-26 12:15:46.191  32094-32094/com.example.android E/dalvikvm﹕ >>>>> com.example.android [ userId:0 | appId:10288 ]
    01-26 12:15:46.191  32094-32094/com.example.android D/dalvikvm﹕ Late-enabling CheckJNI
    01-26 12:15:46.261  32094-32094/com.example.android E/dalvikvm﹕ Could not find class 'io.fabric.sdk.android.Kit[]', referenced from method com.example.android.ExampleApplication.onCreate
    01-26 12:15:46.261  32094-32094/com.example.android W/dalvikvm﹕ VFY: unable to resolve new-array 10457 ([Lio/fabric/sdk/android/Kit;) in Lcom/example/android/ExampleApplication;
    01-26 12:15:46.261  32094-32094/com.example.android D/dalvikvm﹕ VFY: replacing opcode 0x23 at 0x0007
    01-26 12:15:46.261  32094-32094/com.example.android W/dalvikvm﹕ Unable to resolve superclass of Lcom/crashlytics/android/Crashlytics; (8949)
    01-26 12:15:46.261  32094-32094/com.example.android W/dalvikvm﹕ Link of class 'Lcom/crashlytics/android/Crashlytics;' failed
    01-26 12:15:46.261  32094-32094/com.example.android D/dalvikvm﹕ DexOpt: unable to opt direct call 0x3705 at 0x12 in Lcom/example/android/ExampleApplication;.onCreate
    01-26 12:15:46.261  32094-32094/com.example.android I/MultiDex﹕ VM with version 1.6.0 does not have multidex support
    01-26 12:15:46.261  32094-32094/com.example.android I/MultiDex﹕ install
    01-26 12:15:46.261  32094-32094/com.example.android I/MultiDex﹕ MultiDexExtractor.load(/data/app/com.example.android-1.apk, false)
    01-26 12:15:46.271  32094-32094/com.example.android I/MultiDex﹕ loading existing secondary dex files
    01-26 12:15:46.271  32094-32094/com.example.android I/MultiDex﹕ load found 1 secondary dex files
    01-26 12:15:46.276  32094-32094/com.example.android I/MultiDex﹕ install done
    01-26 12:15:46.281  32094-32094/com.example.android I/PersonaManager﹕ getPersonaService() name persona_policy
    01-26 12:15:46.291  32094-32094/com.example.android D/AndroidRuntime﹕ Shutting down VM
    01-26 12:15:46.291  32094-32094/com.example.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41887c08)
    01-26 12:15:46.296  32094-32094/com.example.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.example.android, PID: 32094
        java.lang.NoClassDefFoundError: io.fabric.sdk.android.Kit[]
                at com.example.android.ExampleApplication.onCreate(ExampleApplication.java:16)
                at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
                at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4581)
                at android.app.ActivityThread.access$1600(ActivityThread.java:161)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:157)
                at android.app.ActivityThread.main(ActivityThread.java:5356)
                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:1265)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
                at dalvik.system.NativeStart.main(Native Method)
    01-26 12:15:52.016  32094-32094/com.example.android I/Process﹕ Sending signal. PID: 32094 SIG: 9
    

    build.gradle

      buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/repo' }
        }
    
        dependencies {
            classpath 'io.fabric.tools:gradle:1.14.4'
        }
    }
    apply plugin: 'com.android.application'
    //Put Fabric plugin after Android plugin
    apply plugin: 'io.fabric'
    
    repositories {
        maven { url 'https://raw.github.com/beshkenadze/dozer/mvn-repo' }
        maven { url 'https://maven.fabric.io/repo' }
    }
    
    ...
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        ...
        // Crashlytics Kit
        compile('com.crashlytics.sdk.android:crashlytics:2.2.0@aar') {
            transitive = true
        }
    }
    
    afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = []
            }
            dx.additionalParameters += '--multi-dex'
            dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
        }
    }
    

    ExampleApplication.java

        package com.example.android;
    
    import android.support.multidex.MultiDexApplication;
    
    import com.crashlytics.android.Crashlytics;
    
    import io.fabric.sdk.android.Fabric;
    
    public class ExampleApplication extends MultiDexApplication {
    
        private ExampleManager mManager;
    
        @Override
        public void onCreate() {
            super.onCreate();
            Fabric.with(this, new Crashlytics());
    
            mManager = ExampleManager.getInstance();
            mManager.init(getApplicationContext());
        }
    }
    

    multidex.keep

    android/support/multidex/BuildConfig.class
    android/support/multidex/MultiDex$V14.class
    android/support/multidex/MultiDex$V19.class
    android/support/multidex/MultiDex$V4.class
    android/support/multidex/MultiDex.class
    android/support/multidex/MultiDexApplication.class
    android/support/multidex/MultiDexExtractor$1.class
    android/support/multidex/MultiDexExtractor.class
    android/support/multidex/ZipUtil$CentralDirectory.class
    android/support/multidex/ZipUtil.class
    com/example/android/ExampleApplication.class
    

    progurad-rules.pro

    -dontoptimize
    -dontobfuscate
    #-optimizationpasses 5
    -printusage unused.txt
    -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -dontpreverify
    -keepattributes SourceFile,LineNumberTable
    -keepattributes *Annotation*
    -keepattributes InnerClasses
    
    #Project
    
    -keep public class com.example.android.** { *; }
    -dontwarn com.example.android.**
    -dontwarn com.example.android.db.**
    -keep public class com.example.android.db.** { *; }
    
    # JavascriptInterface Proguard RULES
    -keepclassmembers class * {
        @android.webkit.JavascriptInterface <methods>;
    }
    
    -keepattributes JavascriptInterface
    -keep public class com.example.android.ui.view.EditorView$EditorInterface
    -keep public class * implements com.example.android.ui.view.EditorView$EditorInterface
    -keepclassmembers class com.example.android.ui.view.EditorView$EditorInterface {
        <methods>;
    }
    
    # Libs
    #-libraryjars libs/AF-Android-SDK-v2.3.1.11.jar
    #-libraryjars libs/aws-android-sdk-1.7.1.1-core.jar
    #-libraryjars libs/aws-android-sdk-1.7.1.1-s3.jar
    #-libraryjars libs/FlurryAnalytics_3.3.3.jar
    #-libraryjars libs/Parse-1.4.3.jar
    #-libraryjars libs/google-play-services-STRIPPED.jar
    #-libraryjars ../bypass-library/libs/bypass.jar
    
    # Models
    -keep class com.example.android.api.data.** { *; }
    -keep class com.example.android.model.** { *; }
    
    # Bypass
    -keep class in.uncod.android.bypass.** { *; }
    
    # Butterknife
    -dontwarn butterknife.internal.**
    -keep class **$$ViewInjector { *; }
    -keepnames class * { @butterknife.InjectView *;}
    
    # Parse.com
    -dontwarn com.parse.FacebookAuthenticationProvider*
    -dontwarn com.parse.FacebookAuthenticationProvider
    -dontwarn com.parse.ParseFacebookUtils
    -dontwarn com.parse.**
    -keep class com.parse.** { *; }
    
    # AWS SDK for Android
    -keep class org.apache.commons.logging.**               { *; }
    -keep class com.amazonaws.services.sqs.QueueUrlHandler  { *; }
    -keep class com.amazonaws.javax.xml.transform.sax.*     { public *; }
    -keep class com.amazonaws.javax.xml.stream.**           { *; }
    -keep class com.amazonaws.services.**.model.*Exception* { *; }
    -keep class org.codehaus.**                             { *; }
    -keep class com.amazonaws.internal.config.** { *; }
    -keepattributes Signature,*Annotation*
    
    -dontwarn javax.xml.stream.events.**
    -dontwarn com.fasterxml.jackson.**
    -dontwarn org.apache.commons.logging.impl.**
    -dontwarn org.apache.http.conn.scheme.**
    -dontwarn com.amazonaws.AmazonWebServiceRequest
    -dontwarn com.amazonaws.ClientConfiguration
    -dontwarn com.amazonaws.DefaultRequest
    -dontwarn com.amazonaws.RequestClientOptions
    -dontwarn com.amazonaws.auth.**
    -dontwarn com.amazonaws.http.AmazonHttpClient
    -dontwarn com.amazonaws.http.ExecutionContext
    -dontwarn com.amazonaws.http.impl.**
    -dontwarn com.amazonaws.internal.config.HttpClientConfig
    -dontwarn com.amazonaws.internal.config.InternalConfig
    -dontwarn com.amazonaws.internal.config.SignerConfig
    -dontwarn com.amazonaws.metrics.ServiceLatencyProvider
    -dontwarn com.amazonaws.org.apache.http.**
    -dontwarn com.amazonaws.retry.RetryPolicy
    -dontwarn com.amazonaws.util.**
    -dontwarn com.amazonaws.org.joda.**
    -dontwarn com.amazonaws.javax.**
    -dontwarn org.apache.commons.**
    
    # Android
    -keep public class * extends android.app.Activity
    -keep public class * extends android.webkit.WebView
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Fragment
    -keep public class * extends android.app.ListActivity
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keepclasseswithmembers class * {
        native <methods>;
    }
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    -keepclassmembers class * {
        public void onClickUpdate(android.view.View);
    }
    
    -keep class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator *;
    }
    
    -keep class * extends java.util.ListResourceBundle {
       protected Object[][] getContents();
    }
    
    
    # Google API
    -keep class com.google.** { *;}
    -keep interface com.google.** { *;}
    -dontwarn com.google.**
    
    -dontwarn sun.misc.Unsafe
    -dontwarn com.google.common.collect.MinMaxPriorityQueue
    -keepattributes *Annotation*,Signature
    -keep class * extends com.google.api.client.json.GenericJson {
    *;
    }
    
    -keep class * extends java.util.ListResourceBundle {
        protected Object[][] getContents();
    }
    
    -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
        public static final *** NULL;
    }
    
    -keepnames @com.google.android.gms.common.annotation.KeepName class *
    -keepclassmembernames class * {
        @com.google.android.gms.common.annotation.KeepName *;
    }
    
    -keepnames class * implements android.os.Parcelable {
        public static final ** CREATOR;
    }
    
    
    # Squareup
    -dontwarn com.squareup.okhttp.**
    
    # Joda-Time
    -dontwarn org.joda.time.**
    
    # EventBus
    -keepclassmembers class ** {
        public void onEvent*(**);
    }
    
    # Annotation
    -keepattributes *Annotation*
    
    # Retrofit
    -keep class com.google.gson.** { *; }
    -keep class com.google.inject.** { *; }
    -keep class org.apache.http.** { *; }
    -keep class org.apache.james.mime4j.** { *; }
    -keep class javax.inject.** { *; }
    -keep class retrofit.** { *; }
    -keep class com.example.testobfuscation.** { *; }
    -keepattributes Signature
    -keep class sun.misc.Unsafe { *; }
    -dontwarn rx.**
    
    # Scribe oAuth
    -keep class org.scribe.** {
        *;
    }
    -keep class javax.xml.bind.DatatypeConverter
    -dontwarn javax.xml.bind.DatatypeConverter
    -dontwarn org.scribe.**
    
    #Roundview
    -dontwarn com.makeramen.**
    
    #android.support.v4
    -dontwarn android.support.v4.**
    
    -keepclasseswithmembers class io.fabric.sdk.android.** {
      *;
    }
    
    -keep public class * extends io.fabric.sdk.android.Kit.**
    -keep class * implements io.fabric.sdk.android.KitGroup.**
    
    0 讨论(0)
  • 2020-12-20 17:07

    I just figured it out with a hunch! I recently had to add multi-dex support after upgrading to the new Fabric framework, and I had a feeling that maybe I didn't do it correctly. So after adding these additional changes, now it no longer crashes:

    In my build.gradle, I added an incremental settings:

    dexOptions {
            incremental true
            javaMaxHeapSize "4g"
        }
    

    and an additional dependency:

    compile 'com.android.support:multidex:'
    

    and on my application class I'm extending MultiDexApplication:

    public class TownsquareEvents extends android.support.multidex.MultiDexApplication
    
    0 讨论(0)
  • 2020-12-20 17:07

    Additional info two years later : It seems that the problem occurs only on devices running Android < 5 (if that helps someone to narrow their search of the crash...)

    0 讨论(0)
提交回复
热议问题