错误:重复条目:com/google/android/gms/common/api/zze.class

4
我正在使用Firebase创建Facebook登录系统。但是当我编译项目时,会出现以下错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zze.class

build.gradle (project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.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 {
        jcenter()
    }
}

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

build.gradle(应用程序):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.zihadrizkyef.belajar_facebooklogin"
        minSdkVersion 19
        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'
        }
    }
}

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:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.google.firebase:firebase-core:10.0.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    testCompile 'junit:junit:4.12'
}

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

仅供参考:将您的 buildToolsVersion 更改为 25.0.0,我认为您不需要在此处使用 multiDex,因为您的项目中没有包含大型库。因此,您需要将其删除或注释掉。 - ישו אוהב אותך
如果我删除它,Android Studio 会给我 multidex 错误。我不记得错误的引用了。 - zihadrizkyef
你的项目的libs目录中是否包含了其他库? - ישו אוהב אותך
抛开这个不谈,使用 compile 'com.facebook.android:facebook-android-sdk:4.+' 怎么样? - ישו אוהב אותך
仍然给我相同的错误 `错误:执行任务“:app:transformClassesWithJarMergingForDebug”失败。
com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/common/api/zze.class`
- zihadrizkyef
显示剩余3条评论
3个回答

5

所有Firebase库必须是相同的版本。使用10.0.0版本的firebase-auth

compile 'com.google.firebase:firebase-core:10.0.0'
compile 'com.google.firebase:firebase-auth:10.0.0'

0
在我的项目中,有一些重复的文件存在于不同的JAR或LIB中,我在我的应用程序build.gradle中添加了一些代码,如下所示:
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INFTICE.txt'
    exclude 'META-INFTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INFtice.txt'
    exclude 'META-INFcense.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/MANIFEST.MF'
    exclude 'META-INF/maven/com.google.protobuf/protobuf-java/pom.xml'
    exclude 'META-INF/maven/com.google.protobuf/protobuf-java/pom.properties'
}

它可以工作。

我认为您可能包含了其他包括“com/google/android/gms/common/api/zze.class”或整个包的jar文件。

UMeng jars包含protobuf,并且我的模型也包含,因此我在build.gradle的packagingOptions中排除了两个protobuf-java文件。


我应该把那段代码放在哪里? 顺便说一下,我不知道哪个JAR文件是重复的。 - zihadrizkyef

0
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.google.firebase:firebase-core:10.0.0'
compile ('com.google.firebase:firebase-auth:9.8.0') {
    exclude group: 'com.google.android.gms'
}
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接