简体   繁体   English

如何解决java.util.zip.ZipException?

[英]How to resolve java.util.zip.ZipException?

Whever I try to debug and deploy my android application (in Android Studio 0.9) I get the following error: 当我尝试调试和部署我的Android应用程序(在Android Studio 0.9中)时,我收到以下错误:

Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/multidex/BuildConfig.class

To make things clear here is a brief history of my actions: 为了清楚起见,这是我行动的简要历史:

  1. This morning the project was working fine 今天早上这个项目工作正常
  2. Added some additional classes and methods 添加了一些额外的类和方法
  3. Broke the limit and received this error: Unable to execute dex: method ID not in [0, 0xffff]: 65536 中断了限制并收到此错误: Unable to execute dex: method ID not in [0, 0xffff]: 65536
  4. Decided to add multiDex support to my project as reducing the dependencies was not an option 决定为我的项目添加multiDex支持,因为减少依赖项不是一种选择

Since then I keep getting the described error just after adding multiDex to my project by following this SO post Using Gradle to split external libraries in separated dex files to solve Android Dalvik 64k methods limit . 从那时起,我继续在将multiDex添加到我的项目之后,通过遵循此SO帖子使用Gradle将外部库拆分为单独的dex文件来解决Android Dalvik 64k方法限制

Here is my build.gradle file: 这是我的build.gradle文件:

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

    defaultConfig {
        applicationId "com.stackoverflow.application"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        preDexLibraries = false
    }
}

afterEvaluate {
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = []
        }
        dx.additionalParameters += '--multi-dex'
        dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':viewPagerIndicatorLibrary')
    compile 'com.google.android:multidex:0.1'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'de.greenrobot:eventbus:2.2.1'
    compile 'se.emilsjolander:stickylistheaders:2.5.1'
    compile 'joda-time:joda-time:2.5'
    compile 'com.makeramen:roundedimageview:1.4.0'
    compile 'javax.inject:javax.inject:1'
    compile 'com.squareup.picasso:picasso:2.3.4'
    compile 'com.googlecode.libphonenumber:libphonenumber:6.3.1'
    compile('com.google.api-client:google-api-client-gson:1.18.0-rc') {
        exclude module: 'httpclient'
    }

    compile 'com.google.android.gms:play-services:6.1.71'
    compile('com.google.api-client:google-api-client:1.17.0-rc') {
        exclude(group: 'xpp3', module: 'xpp3')
        exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
        exclude(group: 'junit', module: 'junit')
        exclude(group: 'com.google.android', module: 'android')
    }
    compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
        exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
    }
    compile('com.google.http-client:google-http-client-android:1.17.0-rc') {
        exclude(group: 'com.google.android', module: 'android')
    }
    compile 'com.google.guava:guava:18.0'
}

I also have another project dependencies to use the viewPagerIndicator library as well as a few jars in my /libs folder: 我还有另一个项目依赖项来使用viewPagerIndicator库以及my / libs文件夹中的几个jar:

  • android-async-http-1.4.6.jar Android的异步HTTP-1.4.6.jar
  • guice-3.0-no_aop.jar 吉斯-3.0-no_aop.jar
  • jsr305-1.3.9.jar jsr305-1.3.9.jar
  • roboguice-2.0.jar roboguice-2.0.jar

Any advice on how I could resolve this problem without removing any of my needed dependencies is welcomed ! 我欢迎任何有关如何解决此问题而不删除任何所需依赖项的建议!

Thread is a bit old, but I got this error too. 线程有点旧,但我也得到了这个错误。

My problem was that I used two different com.google.android.gms:play-services Versions in my gradle file. 我的问题是我在gradle文件中使用了两个不同的com.google.android.gms:play-services版本。

compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.3.0' // WRONG!

Make sure, that you always use same versions like: 确保您始终使用相同的版本:

compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'

Edit: This is a bug and a fix is due. 编辑:这是一个错误,修复到期。 See https://code.google.com/p/android/issues/detail?id=81804 请参阅https://code.google.com/p/android/issues/detail?id=81804

I have this problem too, and I don't have an answer. 我也有这个问题,我也没有答案。 But here's what I can add: 但这是我可以添加的内容:

The class BuildConfig is a magic class generated as part of the build process. BuildConfig类是一个魔术类,是作为构建过程的一部分生成的。 For some reason, there exists a version with the same fully-qualified name ( android.support.multidex.BuildConfig ) in both mutildex-1.0.0 and multidex-instrumentation-1.0.0 aars. 出于某种原因,在mutildex-1.0.0multidex-instrumentation-1.0.0 aars中都存在具有相同完全限定名称( android.support.multidex.BuildConfig )的版本。

I don't believe we have done anything wrong. 我不相信我们做错了什么。 I think this is a symptom of being on the cutting-edge. 我认为这是一个处于最前沿的症状。 I raised a bug report . 我提出了一个错误报告

To diagnose and fix this problem, run this gradle command: 要诊断并修复此问题,请运行以下gradle命令:

./gradlew clean app:dependencies

this will list all of the dependencies in your app in a tree. 这将在树中列出您应用中的所有依赖项。 Search the results for the offending duplicate class and add 搜索有问题的重复类的结果并添加

compile('naughty.library') {
    exclude group: 'foo', module: 'bar'
}

to remove the duplicate. 删除副本。

I recently had this error, and after looking at my "External Libraries" in Android studio, it turns out one of my libraries had been included under two version numbers. 我最近遇到了这个错误,在Android工作室查看我的“外部库”之后,事实证明我的一个库已被包含在两个版本号下。 (In this case it was wire-runtime 1.5.1 and 1.5.2). (在这种情况下,它是wire-runtime 1.5.1和1.5.2)。

What I would recommend is to look inside "External Libraries" in your Project view, and see if there are any redundant libraries there. 我建议的是在Project视图中查看“External Libraries”,看看那里是否有任何冗余库。 It includes transitive dependencies as well so you might find something there that surprises you. 它还包含传递依赖关系,因此您可能会发现令您惊讶的内容。

1.update google play service 1.update谷歌播放服务

2.add 2.加

compile 'com.google.android.gms:play-services-fitness:8.1.0'
compile 'com.google.android.gms:play-services-wearable:8.1.0'

instead of compile 'com.google.android.gms:play-services:8.1.0' 而不是compile 'com.google.android.gms:play-services:8.1.0'

in build.gradle file. 在build.gradle文件中。

3. 3。

defaultConfig {
    multiDexEnabled true
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

In my case the reason was Facebook Android SDK. 在我的情况下,原因是Facebook Android SDK。 Just exclude transitive dependency: 只是排除传递依赖:

compile('com.facebook.android:facebook-android-sdk:+') {
    exclude group: 'com.android.support', module: 'multidex'
}

In your case it can be some other dependency - just sort through them one by one and you'll find the one who has transitive multidex dependency. 在你的情况下,它可能是一些其他的依赖 - 只需逐个排序,你会发现具有传递multidex依赖的multidex

If you enable multiDex, you should stop doing the logic in afterEvaluate {} . 如果启用multiDex,则应该在afterEvaluate {}停止执行逻辑。 The multi-dex support will take care of the main dex list for you. multi-dex支持将为您处理主要的dex列表。

This type of error like duplicate entry occurs when you some class is at more than one place. 当某个类位于多个位置时,会发生类似重复输入的错误。 To overcome this problem , Simple search the class which shows duplicate entry in project. 要解决此问题,只需搜索显示项目中重复条目的类。 It will show you all paths where this class present more than one place. 它将显示此类出现多个地方的所有路径。 In Windows CNTRL+N is keyboard shortcut for search in files. 在Windows中CNTRL + N是用于在文件中搜索的键盘快捷键。 Simple try to remove one of the lib or file and the problem is solved. 简单的尝试删除其中一个lib或文件,问题解决了。

tools:overrideLibrary="com.google.android.gms.location, com.google.android.gms.internal"

我的诀窍(我想你应该用你使用的任何谷歌库改变位置)

You are adding a library like this 您正在添加这样的库
(A). (一个)。 compile files('libs/YOUR_LIBRARY.jar') 编译文件('libs / YOUR_LIBRARY.jar')
and this library package already available in your code. 并且您的代码中已经提供了此库包。
comment it like or remove this line 评论它或删除此行
//compile files('libs/YOUR_LIBRARY.jar') //编译文件('libs / YOUR_LIBRARY.jar')

How to know duplicate-copy of library in your project: 如何知道项目中库的重复副本:
unzip your "YOUR_LIBRARY.jar" and see the same class name in your code. 解压缩您的“YOUR_LIBRARY.jar”并在代码中看到相同的类名。

转到File/Invalidate Chaches/Restart ,您的问题已解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM