发生错误
在尝试使用gradle构建android studio项目时,我收到此错误:
Execution failed for task ':app:transformResourcesWithMergeJavaResForPlainDebug'.
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException:
Duplicate files copied in APK org/apache/log4j/lf5/config/defaultconfig.properties
File1: ...\app\libs\tn5250j.jar
File2: ...\app\build\intermediates\exploded-aar\xxx\xxx\jars\libs\log4j-1.2.17.jar
在包含的两个.jars
中,使用了log4j
库。我必须将两个库都包含到我的android应用程序中。其中一个是.aar
文件,另一个是.jar
。Gradle 设置
我的
build.gradle
的依赖项:dependencies {
debugCompile 'xxx@aar'
releaseCompile 'xxx@aar'
compile files('libs/commons-net-3.5.jar')
compile files('libs/jackson-core-2.8.1.jar')
compile files('libs/jackson-databind-2.8.1.jar')
compile files('libs/jackson-annotations-2.8.1.jar')
compile files('libs/tn5250j.jar')
}
我的build.gradle
中的打包选项:packagingOptions {
exclude 'main/AndroidManifest.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
}
最佳答案
我不知道tn5250j.jar
是什么,但它看起来像是在里面打包log4j
的UBER jar。您可以从构建中排除log4j
依赖关系(因为它包装在tn5250j.jar
中),或者您可以对tn5250j.jar
进行调整以删除log4j
并使用“调整过的” jar。例如:
dependencies {
...
compile files("$buildDir/tweaked/tn5250j-tweaked.jar")
}
task tweakTn5250j(type: Zip) {
from zipTree('libs/tn5250j.jar').matching {
exclude 'org/apache/log4j/**'
}
destinationDir = "$buildDir/tweaked"
archiveName = 'tn5250j-tweaked.jar'
}
classes.dependsOn tweakTn5250j
关于android - Gradle:不能排除两个log4j依赖关系之一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40262162/