java.util.zip.ZipException:packageAllDebugClassesForMultiDex期间的重复条目

问题描述 投票:114回答:20

我不确定这个错误意味着什么。

Execution failed for task ':excelSior:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class

我目前正在使用android-support-v4.jar作为我的图书馆

dependencies {
    compile project(':addThisSDK')
    compile project(':centeredContentButton')
    compile project(':googleplayservices_lib')
    compile files('libs/adxtag2.4.6.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-debug.jar')
    compile files('libs/commons-lang-2.6.jar')
    compile files('libs/crittercism_v4_4_0_sdkonly.jar')
    compile files('libs/dd-plist.jar')
    compile files('libs/FiksuAndroidSDK_4.1.1.jar')
    compile files('libs/iqengines-sdk-barcode.jar')
    compile files('libs/irEventTracker-1.2.jar')
    compile files('libs/jolt-core-0.0.7.jar')
    compile files('libs/json-utils-0.0.7.jar')
    compile files('libs/jsoup-1.7.2.jar')
    compile files('libs/kooaba-api-v4-java.jar')
    compile 'com.android.support:multidex:1.0.0'
}

在gradle sync期间,错误不会显示。就在我尝试运行应用程序时

可能是什么问题呢?

android android-gradle android-support-library android-multidex
20个回答
64
投票

您需要检查是否已插入v4库并编译库?您不得在应用程序或依赖程序中重复库。

删除重复库,以便只剩下一个V4。

在你的应用程序目录build.gradle文件添加此命令:

android{


    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude group: 'com.android.support', module: 'support-annotations'
    }

}

这个对我有用!你可以尝试一下!


1
投票

这是因为您添加了一个库并且多次依赖于模块。

在我的例子中,我添加了一个库作为模块和gradle依赖。

删除一个添加库的源(我删除了gradle依赖)解决了我的问题。


0
投票

对于错误:任务执行失败':app:transformClassesWithJarMergingForDebug'com.android.build.api.transform.TransformException java.util.zip.ZipException重复条目com / google / gson / annotations / Expose.class

这是我做的:

1)删除gson-2.5.jar文件。 2)配置{all * .exclude module:'gson-2.5'}


0
投票

我已经遇到了这个问题,因为我手动复制了libs中的jar,并提到了gradle文件中的依赖项。您还要检查项目结构,是否在libs或项目文件夹中的任何其他文件夹中复制相同的jar文件。


0
投票

升级android SDK后我遇到了同样的问题。我能够在buildToolsVersion '23.0.1'中运行应用程序,当我改为buildToolsVersion '24.0.3'时,我得到了同样的错误

我通过compileSdkVersion 24将我的java版本从1.7更新为1.8来解决了这个问题


0
投票

这个问题花了我一整天。我最终将firebase-ui库版本从2.0.0降级到1.2.0,并在Project level build.gradle文件中添加了以下代码:

allprojects {
    repositories {
        jcenter()

        // Add the following code to your project level build.gradle
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}

0
投票

我也有这个问题因为我编译'com.android.support:appcompat-v7:24.0.0-alpha1'但我添加了recyclerview liberary compile'c​​om.android.support:recyclerview-v7:24.0.2'..我改变了与compat相同的版本(24.0.2 intead of 24.0.0)。

我得到了答案。可能会对某人有所帮助。


0
投票

在我的情况下,在build.gradle中setmultiDexEnable = true之后出现了提到的“重复条目”错误。

我得到的确切错误如下:

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

所以我首先在Android Studio中使用ctrl + n搜索导致“重复输入”错误的类并搜索com / google / android / gms / internal / zzqx.class然后它显示2个gms类的条目,其中包含一个版本8.4.0和1版本11.6.0。

为了解决这个问题,我使用了11.6.0并且它是固定的例子

    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:8.4.0"
    compile "com.google.android.gms:play-services-ads:11.6.0"

    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:11.6.0"
    compile "com.google.android.gms:play-services-ads:11.6.0"

重建固定。


0
投票

在我的情况下,确切的错误如下

':机器人:transformClassesWithJarMergingForDebug'。

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / google / android / gms / internal / zzqx.class

我正在使用另一个版本的google apis,即在一个模块gradle文件中

if (!project.hasProperty('gms_library_version')) {
        ext.gms_library_version = '8.6.0'
   }

但是在其他模块版本11.6.0中如下

   compile "com.google.android.gms:play-services-ads:11.6.0"
    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:11.6.0"

然而,为了找到这个我在android工作室做了一个ctrl + n并输入了类名zzqx.class然后它显示了为这个类提取的2个jar文件,然后我明白我正在使用版本8.6.0。在将8.6.0更改为11.6.0并重建项目时,问题已得到修复。

希望这可以帮助 。

更多关于这里https://www.versionpb.com/tutorials/step-step-tutorials-libgdx-basic-setup-libgdx/implementing-google-play-services-leaderboards-in-libgdx/


0
投票

对我来说,当我意外地添加时发生了类似的事情

apply plugin: 'kotlin-android'

到我的android库模块。删除该行可修复该问题。


-1
投票

试试这个:

android {
configurations {
        all*.exclude  module: 'PhotoView'  //去除重复依赖库
    }
}

82
投票

你可能现在已经解决了这个问题但是这样做并没有得到解决,请尝试将此添加到你的build.gradle

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

-1
投票

只需擦除android / support / v4 / util / TimeUtils.class


25
投票

在重新导入旧的Eclipse项目时,我也遇到过这种问题。它在项目中发生了一些旧的依赖项作为jar文件。

只是删除

编译fileTree(dir:'libs',包括:'* .jar')

在gradle文件中

并在gradle文件中添加依赖项。

这个对我有用 ..


13
投票

在我的情况下,在build.gradle中设置multiDexEnable=true之后出现了提到的“重复条目”错误。

为了完全解决错误,首先要看看Configure Apps with Over 64K Methods(特别是“使用Gradle为Multidex配置你的应用程序”)。

此外,在Android Studio中使用ctrl + n搜索导致“重复输入”错误的类的出现。确定包含副本的模块和依赖项,并将其从构建中排除,例如:

compile ('org.roboguice:roboguice:2.0') {
    exclude module: 'support-v4'
}

我不得不尝试多个模块标签,直到它工作。排除“support-v4”解决了与“java.util.zip.ZipException:重复条目:android / support / v4 / *”相关的问题


9
投票

我的理解是有相同API的重复引用(可能不同的版本号)。从命令行构建时,调试应该相当容易。

从命令行尝试./gradlew yourBuildVariantName --debug

违规项目将是第一次失败。示例可能如下所示:

14:32:29.171 [INFO] [org.gradle.api.Task] INPUT: /Users/mydir/Documents/androidApp/BaseApp/build/intermediates/exploded-aar/theOffendingAAR/libs/google-play-services.jar

14:32:29.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':BaseApp:packageAllyourBuildVariantNameClassesForMultiDex'

14:32:29.172 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :BaseApp:packageAllyourBuildVariantNameClassesForMultiDex FAILED'

在上面的例子中,我包含在我的libs目录(theOffendingAAR)中的aar文件包含了Google Play Services jar(是的,但我知道。),而我的BaseApp构建文件使用了位置服务:

compile 'com.google.android.gms:play-services-location:6.5.87'

您可以安全地从构建文件中删除有问题的项目,清理并重建(如有必要,请重复)。


8
投票

检查您的依赖项版本,您必须具有兼容的版本,特别注意com.google包,必须具有相同的版本,如:

compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'

两者都是8.3.0,如果你有另一个版本编译将抛出该异常。


5
投票

简单从依赖项gradle.project中删除Jar文件作为v7并运行您的项目


5
投票

对于Expose.class错误,即

java.util.zip.ZipException:重复条目:com / google / gson / annotations / Expose.class

使用以下代码

configurations {
    all*.exclude  module: 'gson'
}

3
投票

找出lib取决于支持v4,并将其排除。

build.gradle中的代码是这样的:

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
    // http://stackoverflow.com/a/30931887/5210
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'
}

在我的情况下,lib'espresso'有一个名为support-v4的jar,在我的项目'app'中有相同的support-v4,在导入espresso时不包括support-v4。

PS:看来compile project无法与exclude合作

© www.soinside.com 2019 - 2024. All rights reserved.