简体   繁体   中英

Android app error java.lang.NoClassDefFoundError when using firebase

I have an app that uses firebase to show ads. The problem is that some devices (seems to be only Android 4.4 devices) crashes. Here is the crash report:

java.lang.NoClassDefFoundError: 
  at com.google.firebase.FirebaseApp.initializeApp (Unknown Source)
  at com.google.firebase.provider.FirebaseInitProvider.onCreate (Unknown Source)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1591)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1562)
  at com.google.firebase.provider.FirebaseInitProvider.attachInfo (Unknown Source)
  at android.app.ActivityThread.installProvider (ActivityThread.java:5035)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:4627)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4567)
  at android.app.ActivityThread.access$1800 (ActivityThread.java:138)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1299)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5262)
  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:851)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:667)
  at dalvik.system.NativeStart.main (Native Method)

I guess the error may have to do with versions of some of my dependencies.

Here's dependencies in the top level gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.3'
    classpath 'com.google.gms:google-services:1.3.0-beta1'
}

And my app gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.google.android.gms:play-services:9.6.0'
}

Any hints would be helpful! Thanks in advance!

these could be the reasons: 1.Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. 2. If a class was present during compile time but not available in java classpath during runtime.

there are several ways rectify it.

if it is maven project then add jar dependency in your pom.xml: else add jar to project lib folder, add the jar to class path from build configuration

You are using very old versions of libraries, update them all and don't use beta. And also if you are not using gms:play-services features, remove it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM