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

时间:2015-12-16 23:57:43

标签: android firebase android-gradle build.gradle

我正在尝试将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$2.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
}

任何人都可以帮我解决这个错误吗?任何答案都将不胜感激,谢谢!

2 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:1)

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

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

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