Java.util.zip.ZipException: duplicate entry: com/google/common/base/FinalizableReference.class Java.util.zip.ZipException: 重复条目:com/google/common/base/FinalizableReference.class

5

为什么我会得到这个错误?当我同步Gradle时,它不会发生,但当我运行项目时,我却得到了这个错误。

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/common/base/FinalizableReference.class

我不知道是哪个依赖项导致了这个错误。我的依赖项如下:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:customtabs:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:percent:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.facebook.android:facebook-android-sdk:4.19.0'
    compile 'com.google.android.gms:play-services-auth:11.0.0'
    compile 'com.google.android.gms:play-services-location:11.0.0'
    compile 'com.google.android.gms:play-services-maps:11.0.0'
    compile 'com.google.android.gms:play-services-places:11.0.0'
    compile 'com.google.maps.android:android-maps-utils:0.3.4'
    compile 'io.nlopez.smartlocation:library:3.3.1'
    compile 'com.appeaser.sublimenavigationviewlibrary:sublimenavigationviewlibrary:0.0.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    compile 'com.afollestad:sectioned-recyclerview:0.4.1'
    compile 'com.github.medyo:fancybuttons:1.8.3'
    compile 'com.basgeekball:awesome-validation:2.0'
    compile 'com.github.michaelye.easydialog:easydialog:1.4'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

编辑

我发现这个问题是由Play服务依赖引起的。当我使用 10.2.6 而不是 11.0.0 时,应用程序可以完美运行,我只需更改依赖即可。

compile 'com.google.android.gms:play-services-auth:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-places:10.2.6'

但我想使用最新版本的play-services 11.0.0,但它会出现上述问题。如何解决这个问题?任何帮助将不胜感激。谢谢。


@IntelliJAmiya 仍然是相同的错误。 - Abhishek Singh
我认为这是一个 bug。你可以提出来。 - IntelliJ Amiya
1
@IntelliJAmiya问题解决了,通过移除这一行apply plugin: 'com.google.gms.google-services'。我认为这个问题可以关闭了? - Abhishek Singh
@AbhishekSingh,你怎么能说删除apply plugin 'com.google.gms.google-services'就能解决问题呢? - Jerry Okafor
@Po10cio 使用 Play Service 版本 11.0.1,我们无需删除此行。 - Abhishek Singh
显示剩余2条评论
2个回答

7

问题终于解决了。看起来这是一个bug,谷歌已经在更新版本中解决了这个问题。

使用play服务版本11.0.1

在项目级别的gradle中使用

classpath 'com.google.gms:google-services:3.1.0'


1
你的应用程序肯定无法构建,我最近升级到Firebase和Play服务11.0.0后也遇到了同样的问题,我认为这是一个错误。 - Jerry Okafor
@Breeno 使用 Play 服务版本 11.0.1 - Abhishek Singh
我认为如果它可用,那将解决它。 - Jerry Okafor
2
@Abhishek Singh 我似乎找不到 Google Play Services v11.0.1,如果我将其放入我的 gradle 文件中,它会说找不到它并且无法构建,并且我在 Google 网站 上没有看到任何提及它的信息。你是否在某种测试更新渠道上?暂时我已经回退到可用的 10.2.6 版本。 - Breeno
@Breeno 再次检查你的链接吧。第一行写着Google Play服务已更新至11.0.1版本,此版本修复了影响使用rxjava的应用程序的问题。 - Abhishek Singh
显示剩余3条评论

0
有时候,这个问题是因为包含了不同版本的play-services(或其他库)而发生的。请使用以下命令查看应用程序依赖项: gradle app:dependencies 如果您正在使用Gradle wrapper,则可以使用以下命令: ./gradlew app:dependencies 可能会有一些其他的第三方库正在使用旧版本的库。如果是这种情况,请从第三方库中排除旧库并包含最新的库。
您可以像这样做:
compile ('com.thirdpartylib.android:library-sdk:8.3.0') {
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.android.gms', module: 'play-services-gcm'
        compile 'com.android.support:support-v4:26.0.0'
        compile 'com.android.support:support-annotations:26.0.0'
        compile 'com.google.android.gms:play-services-gcm:11.2.0'
    }

这应该解决任何重复条目,这是问题的主要原因


不好意思,兄弟。这是在“11.0.0”版本中出现的问题,但在后续版本中已经修复了。 - Abhishek Singh

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