java.lang.NoClassDefFoundError:解析失败解析失败:Lcom/google/android/gms/common/internal/zzab;

Posted

技术标签:

【中文标题】java.lang.NoClassDefFoundError:解析失败解析失败:Lcom/google/android/gms/common/internal/zzab;【英文标题】:java.lang.NoClassDefFoundError: Failed resolution Failed resolution of: Lcom/google/android/gms/common/internal/zzab; 【发布时间】:2017-05-10 10:10:14 【问题描述】:

我正在按照教程 (link) 将图像上传到 Firebase 数据库,但出现以下错误。我重新检查了 gradle 依赖项并启用了 multidex 支持,但错误仍然存​​在

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzab;
    at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source)
    at com.paperwrrk.android.storageref.MainActivity.<init>(MainActivity.java:36)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzab" on path: DexPathList[[dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-tubesock-0.0.11_74622aa9da17bf60443b34c100000d076f6631ba-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-support-annotations-25.0.0_416ca7aea2b0e15fba678c97c0d71c330758ffee-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-databind-2.2.2_169f7b55dddecf9b169deccb0ac50ee124eda962-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-core-2.2.2_3ae6e87b0280ab52f712dfb927e3401fe25aa21c-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-jackson-annotations-2.2.2_dd21f43a23482b41eb5ed094fcce68c90eeb0ffd-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_e8156948d2eb9e5ed0b41cc1f9f830e7838bb3b5-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_9056040795c4cf170b00cbf021bf976514542498-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_79b2045e82b81d2f064515f884990a3d2a9f29af-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_2879b3ac18601405060244958a8db64bdb3655f9-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-internal_impl-25.0.0_1ce40cec84eadc9153f026cb869c8b1760c8461a-classes.dex", dex file "/data/data/com.paperwrrk.android.storageref/files/instant-run/dex/slice-firebase-client-jvm-2.3.1_764f8006

Gradle.app

apply plugin: 'com.android.application'

android 
    compileSdkVersion 25
    buildToolsVersion "24.0.3"
    defaultConfig 
        applicationId "com.paperwrrk.android.storageref"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    
    packagingOptions 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    


dependencies 
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
        exclude group: 'com.android.support', module: 'support-annotations'
    )
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.google.firebase:firebase-database:10.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.google.firebase:firebase-auth:9.2.1'
    compile 'com.google.firebase:firebase-storage:9.2.1'
    compile 'com.android.support:multidex:1.0.0'



apply plugin: 'com.google.gms.google-services'

请告诉我这里做错了什么!

【问题讨论】:

【参考方案1】:

大多数时候问题出在 gradle 中。在我将模块应用程序的 firebase-(storage/auth/database) build gradle 更改为相同之前,我遇到了类似的问题,例如 (com.google.firebase:firebase-storage:16.1.0,com.google.firebase:firebase-auth:16.1.0, com.google.firebase:firebase-database:16.1.0)

【讨论】:

【参考方案2】:

我在实施原生广告时遇到了类似的问题并杀死了将近 4 个小时......

最后我发现在不同的模块中有不同的 com.google.android.gms:play-services-ads 版本('17.1.1' 和 '12.0.0')。

将所有版本更改为 17.1.1 后,它解决了我的问题。

【讨论】:

【参考方案3】:

如果您正在为 react-native 项目寻求解决方案,请确保不同模块之间使用相同的版本,并将“+”替换为一些最新的可用版本。

【讨论】:

【参考方案4】:

现在问题出在这里,您在 gradle 的依赖项中使用了不同的版本 所以改变这个

compile 'com.google.firebase:firebase-database:10.0.0'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.google.firebase:firebase-storage:9.2.1'
compile 'com.android.support:multidex:1.0.0'

到这里

compile 'com.google.firebase:firebase-database:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.android.support:multidex:1.0.0'

还有一件事是,现在com.firebae:firebase-client-android 已被弃用,因此您需要将其替换为com.google.firebase:firebase-database:10.0.1,这是https://firebase.google.com/support/guides/firebase-android 的文档

【讨论】:

我在使用 facebook 帐户工具包库时遇到了类似的问题。这个解决方案就像一个魅力!赞!! 从 gradle 3.0 开始,wards 'compile' 已被弃用。请改用“实施”或“API”。 'testCompile' 也已被弃用,请改用 'testImplementation'。 这是一个很好的答案,但就我而言,我的错是在初始化之前使用了分析库。通常使用未初始化的类(库)会导致此错误

以上是关于java.lang.NoClassDefFoundError:解析失败解析失败:Lcom/google/android/gms/common/internal/zzab;的主要内容,如果未能解决你的问题,请参考以下文章