问题
App crashes when i apply crashlytics
on it
FATAL EXCEPTION: main
Process: com.ehs.pk, PID: 20963
java.lang.RuntimeException: Unable to get provider com.crashlytics.android.CrashlyticsInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.CrashlyticsInitProvider" on path: DexPathList[[zip file "/data/app/com.ehs.pk-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.ehs.pk-8, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4585)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.CrashlyticsInitProvider" on path: DexPathList[[zip file "/data/app/com.ehs.pk-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.ehs.pk-8, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4585)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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)
回答1:
I was facing the same issue, is related to the 64k limit "multidex".
I was using multiDexEnabled true
property in build.gradle in defaultConfig
block, under android
one.
As stated in Google documentation
for devices with Android API prior to 21, we need to include the multidex library (implementation 'com.android.support:multidex:1.0.2'
)
and extend MultiDexApplication
in our Application class
回答2:
I have solved this problem by doing the following:
In the Application class:
@Override
public void attachBaseContext(Context base) {
super.attachBaseContext(base);
try {
MultiDex.install(this);
} catch (RuntimeException multiDexException) {
multiDexException.printStackTrace();
}
}
回答3:
We were having the same issue, and disabling instant run in Android Studio seemed to get it working.
On mac Android Studio Settings or Preferences -> Build,Execution,Deployment -> Instant Run.
回答4:
By looking at this part...
Didn't find class ... on path: DexPathList ...
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
of the stack trace you can figure out that your test device is probably pre-Lollipop (Android 5.0) and that you just hit the 64k limit. You can fix it as described here.
回答5:
This could be an issue with Instant Run. Turn off the Instant Run and run the build again. I faced the same issue and it resolved it.
回答6:
When minifyEnabled is true while using firebase or crashlytics this problem may happens. Enabling minifyEnabled shrinks methods and classes names to lowest possible characters (changing names and that raises ClassNotFoundException). Unfortunately, firebase and crashlytics versions had many problem with that. To solve it just tell proguard to not shrink those classes by writing the next lines in proguard file "proguard-rules.pro" as:
-keep class com.crashlytics.** { *; }
-keep class com.google.firebase.*.* { *; }
Now if the problem not go away or it didn't find other classes like yours, then check your base project build.gradle dependencies version of gradle and others. I found these version is free of that error:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.0'
classpath 'io.fabric.tools:gradle:1.25.1'
}
Remeber you can put any classes path into that proguard file so it did not change its name or methods when minify is enabled, and that will help you with other classes "ClassNotFoundException" as well.
Also to test this in debugging, you can adjust debug setting in build.gradle as:
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
回答7:
Just one more case:
In my case, I disabled instant run, added multiDexEnabled true
in my gradle, and added the 'com.android.support:multidex:1.0.3'
to my dependencies, called the MultiDex.install(this);
directly in my custom application, but I still got the same error. The error only occurs in the system Android 4.4. Everything works well on Android 7.0 and 9.0.
Finally, moving the MultiDex.install(this);
from the onCreate(Context)
method to the attachBaseContext(Context)
solved my problem.
So, you should call MultiDex.install(this);
in attachBaseContext(Context)
instead of onCreate(Context)
when you don't plan to extend the MultiDexApplication
directly.
回答8:
If this happens when you run with minifyEnabled true
, add this rule in your proguard-rules.pro
file:
-keep public class com.crashlytics.android.CrashlyticsInitProvider
来源:https://stackoverflow.com/questions/47284814/app-crashes-when-i-apply-crashlytics-on-it