Gradle:不能排除两个log4j依赖关系之一? [英] Gradle: Cant exclude one of two log4j dependencies?
问题描述
在尝试使用gradle构建android studio项目时,我收到此错误:
While trying to build an android studio project with gradle i recieve this error:
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
.
In two included .jars
the library log4j
is used. I must include both libs to my android application. One of them is an .aar
file, the other is a .jar
.
我的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.例如:
I have no idea what tn5250j.jar
is but it looks like it's an UBER jar which is packing log4j
inside. You could either exclude the log4j
dependency from your build (since it's packed inside tn5250j.jar
) or you tweak tn5250j.jar
to remove log4j
and use the "tweaked" jar instead. Eg:
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
这篇关于Gradle:不能排除两个log4j依赖关系之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!