应用程序显示"NoClassDefFoundError: com.google.firebase.FirebaseOptions"上前 19 API 中Android

发布时间: 2016/10/10 20:52:13
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

当开始应用在糖果或较低版本 API,gradle 给此错误。

09-05 03:53:20.660 6775-6775/com.example.MyApp E/AndroidRuntime: FATAL EXCEPTION: main
 java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
     at com.google.firebase.FirebaseApp.zzek(Unknown Source)
     at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
     at android.content.ContentProvider.attachInfo(ContentProvider.java:1214)
     at android.content.ContentProvider.attachInfo(ContentProvider.java:1189)
     at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
     at android.app.ActivityThread.installProvider(ActivityThread.java:4879)
     at android.app.ActivityThread.installContentProviders(ActivityThread.java:4485)
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4425)
     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5103)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:525)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
     at dalvik.system.NativeStart.main(Native Method)

我的 gradle.app 是

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.example.MyApp"
        minSdkVersion 12
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
        transitive = true;
    }
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:cardview-v7:24.2.0'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.firebase:firebase-core:9.0.0' // Tried with and without this
    compile 'com.android.support:multidex:1.0.1'
}

检查每个解决方案提供堆栈中流但没有工作。

更新我的谷歌资料库和谷歌发挥服务。

解决方法 1:

这将属性添加到 application tagmanifest :

android:name="android.support.multidex.MultiDexApplication"

删除 multiDexEnabled true 从 gradle。

赞助商