firebase android中的“NoClassDefFoundError:com.google.firebase.FirebaseOptions”

时间:2016-08-08 09:38:25

标签: android firebase

我尝试将firebase与android应用程序一起使用。 我添加了firebase库并遵循一些教程,但是当我运行时出现错误。

我的傻瓜

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"


defaultConfig {
    applicationId "com.ring"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true


}
buildTypes {
    release {
        minifyEnabled true
        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(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile "com.google.firebase:firebase-auth:9.0.2"
    compile 'com.google.android.gms:play-services-wearable:9.0.2'
    compile 'com.google.android.gms:play-services:9.0.2'
    compile 'com.android.support:multidex:1.0.1'

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

和我的顶级gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
   }

allprojects {
    repositories {


        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

运行项目时的错误是

Java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions

1 个答案:

答案 0 :(得分:1)

清理项目

替换此

compile 'com.firebase:firebase-client-android:2.3.1'
compile "com.google.firebase:firebase-auth:9.0.2"

通过

compile 'com.google.firebase:firebase-core:9.2.1'
compile 'com.google.firebase:firebase-database:9.2.1'
compile 'com.google.firebase:firebase-auth:9.2.1'

并删除此

packagingOptions{
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE/FIREBASE.txt'
exclude 'META-INF/NOTICE'}