build.gradle 编译时出错 'com.firebase:firebase-client-android:2.5.0'

build.gradle error while compiling 'com.firebase:firebase-client-android:2.5.0'

我正在尝试将 Firebase 用于我的 android 应用程序并按照 https://www.firebase.com/docs/android/quickstart.html 的说明进行操作 添加到我的 build.gradle:

dependencies {
    compile 'com.firebase:firebase-client-android:2.5.0+'
}

还有

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

但是当我运行完成项目时。每次我在 运行 项目时都会产生不同的错误,错误是这样的:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/firebase/client/android/AndroidPlatform.class

还有这个

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/firebase/tubesock/Base64.class

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "..."
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        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'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.firebase:firebase-client-android:2.5.0'
} 

这是我项目的build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

谁能帮我解决这个错误?任何答案将不胜感激,谢谢!

看起来你有重复的依赖项,你必须找出哪个库有它。我不确定您的项目中是否还有其他模块,但我会从根项目文件夹 linux/mac:

中的命令行执行
./gradlew -q dependencies yourCoolProject:dependencies --configuration compile

你可以用你的模块名称替换 yourCoolProject,例如 "app" 所以对我来说 运行 它是这样的:

./gradlew -q dependencies app:dependencies --configuration compile

这将使我的项目的所有依赖项成为一棵树。然后我可以看看它抱怨的那些包裹是否被列出了两次。然后我会使用一个排除,以便只使用一个。

您在 build.gradle 中有 firebase 管理的依赖项,在 libs 文件夹中也有 firebase jar 文件。请删除其中之一,以便项目可以正确编译。

这可能是暂时的问题。请尝试删除并重建

compile 'com.firebase:firebase-client-android:2.5.0+'

添加 firebase 依赖项并再次重建后。