Gradle 构建失败:java.util.zip.ZipException:重复条目:org/apache/commons/io/CopyUtils.class
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38706550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle build failed: java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class
提问by insanity_serum
When trying to run the app on my nexus 7, the gradle build fails every time and gives the same error:
尝试在我的 nexus 7 上运行该应用程序时,gradle 构建每次都失败并给出相同的错误:
> com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
org/apache/commons/io/CopyUtils.class
The error seems to indicate that CopyUtils.class
from commons-io
is being included twice in the build process.
该错误似乎表明CopyUtils.class
fromcommons-io
在构建过程中被包含两次。
The full log:
完整日志:
Information:Gradle tasks [:android:assembleDebug]
:android:preBuild UP-TO-DATE
:android:preDebugBuild UP-TO-DATE
:android:checkDebugManifest
:android:preReleaseBuild UP-TO-DATE
:android:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:android:prepareDebugDependencies
:android:compileDebugAidl UP-TO-DATE
:android:compileDebugRenderscript UP-TO-DATE
:android:generateDebugBuildConfig UP-TO-DATE
:android:mergeDebugShaders UP-TO-DATE
:android:compileDebugShaders UP-TO-DATE
:android:generateDebugAssets UP-TO-DATE
:android:mergeDebugAssets UP-TO-DATE
:android:generateDebugResValues UP-TO-DATE
:android:generateDebugResources UP-TO-DATE
:android:mergeDebugResources UP-TO-DATE
:android:processDebugManifest UP-TO-DATE
:android:processDebugResources UP-TO-DATE
:android:generateDebugSources UP-TO-DATE
:android:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:android:compileDebugJavaWithJavac UP-TO-DATE
:android:compileDebugNdk UP-TO-DATE
:android:compileDebugSources UP-TO-DATE
:android:prePackageMarkerForDebug
:android:transformClassesWithJarMergingForDebug FAILED
Error:Execution failed for task
':android:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
org/apache/commons/io/CopyUtils.class
Information:BUILD FAILED
Information:Total time: 11.208 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
Also my build.gradle:
还有我的 build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "org.wildstang.wildrank.android"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.android.support:support-v13:19.+'
compile 'de.congrace:exp4j:0.3.+'
compile 'org.apache.commons:commons-io:1.3.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I seem to now get
我似乎现在得到
Error:(43, 0) Gradle DSL method not found: 'com.android.support:support-v4:24.1.1()' Possible causes:
错误:(43, 0) Gradle DSL 方法未找到:'com.android.support:support-v4:24.1.1()' 可能的原因:
My Gradle wrapper
我的 Gradle 包装器
Wed Jul 06 21:02:27 PDT 2016
2016 年 7 月 6 日星期三 21:02:27 PDT
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
My new gradle file
我的新 gradle 文件
apply plugin: 'com.android.application' //IMPORTANT: 'com.android.application' not
应用插件:'com.android.application' //重要:'com.android.application'不是
android { compileSdkVersion 24 // compile sdk should always be latest buildToolsVersion "24.0.1" // Don't know if this matters
android { compileSdkVersion 24 // 编译 sdk 应该总是最新的 buildToolsVersion "24.0.1" // 不知道这是否重要
defaultConfig {
applicationId "org.wildstang.wildrank.android"
minSdkVersion 14
targetSdkVersion 19 //Looks like this is a new app, why are you using 19 and not 24?
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
}
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') //IMPORTANT
依赖 { compile fileTree(include: ['*.jar'], dir: 'libs') //重要
//Ignore these, I don't think they are important for you, but I needed them to get my test project to compile
// These version numbers worked for me:
compile 'com.android.support:support-v4:24.1.1'{exclude group: 'org.apache.commons', module: 'commons-io' }
compile 'com.android.support:support-v13:24.1.1'{ exclude module: 'commons-io' }
compile 'de.congrace:exp4j:0.3.11'{ exclude module: 'commons-io' }
compile 'org.apache.commons:commons-io:1.3.2'{ exclude module: 'commons-io' }
}
}
回答by Sergii Pechenizkyi
There is an option to fix it on gradle dependency resolution level
有一个选项可以在 gradle 依赖解析级别上修复它
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2')
}
}
Reason of the conflict is that org.apache.commons:commons-io:1.3.2
was pushed by mistake https://stackoverflow.com/a/37421794/624706
冲突的原因是org.apache.commons:commons-io:1.3.2
错误推送https://stackoverflow.com/a/37421794/624706
You can see where dependency is coming from with
你可以看到依赖是从哪里来的
gradle :main:dependencyInsight --configuration compile --dependency commons-io
gradle :main:dependencyInsight --configuration compile --dependency commons-io
回答by Rasool Mohamed
Please use the below code in build.gradle file.
请在 build.gradle 文件中使用以下代码。
configurations {
all*.exclude group: 'org.apache.commons'
}
Enjoy!!!
享受!!!
回答by SUPERCILEX
Edit 2:
编辑2:
I created a forkof the project that compiles and runs on Android Studio 2.2 preview 7. You can also check out the diffif you don't want to redownload the project.
我创建了一个在 Android Studio 2.2 预览版 7 上编译和运行的项目的分支。如果您不想重新下载项目,也可以查看差异。
Edit:
编辑:
Here is a build.gradle
file that compiled for me. I've commented all the important changes:
这是build.gradle
为我编译的文件。我已经评论了所有重要的变化:
apply plugin: 'com.android.application' //IMPORTANT: 'com.android.application' not
android {
compileSdkVersion 24 // compile sdk should always be latest
buildToolsVersion "24.0.1" // Don't know if this matters
defaultConfig {
applicationId "org.wildstang.wildrank.android"
minSdkVersion 14
targetSdkVersion 19 //Looks like this is a new app, why are you using 19 and not 24?
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') //IMPORTANT
//Ignore these, I don't think they are important for you, but I needed them to get my test project to compile
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'
compile 'com.android.support:design:24.1.1'
// These version numbers worked for me:
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:support-v13:24.1.1'
compile 'de.congrace:exp4j:0.3.11'
compile 'org.apache.commons:commons-io:1.3.2'
}
Try what Maxence Barroysaid. If that doesn't work, check out this answer:
试试Maxence Barroy所说的。如果这不起作用,请查看此答案:
compile('com.example:some-dependency:4.2') {
exclude module: 'commons-io'
}
Since I don't know what your build.gradle
file looks like, I can't really help you, but check out this answertoo. Also, make sure you have the latest version of Gradle 'com.android.tools.build:gradle:2.2.0-alpha6'
由于我不知道您的build.gradle
文件是什么样的,因此我无法真正帮助您,但也请查看此答案。另外,请确保您拥有最新版本的 Gradle'com.android.tools.build:gradle:2.2.0-alpha6'
回答by ?zer ?zcan
Also, you can check the gradle version. Above properties should cause of merge conflicts.
此外,您可以检查 gradle 版本。以上属性应该会导致合并冲突。
gradle-wrapper.properties
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
build.gradle
构建.gradle
classpath 'com.android.tools.build:gradle:2.1.3'
And please try the above properties.
并请尝试上述属性。
gradle-wrapper.properties
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
build.gradle
构建.gradle
classpath 'com.android.tools.build:gradle:2.3.3'
回答by Neeraj Singh
compile('org.apache.commons:commons-io:1.3.2') {
exclude module: 'commons-io'
}
try it..
试试看..