android - Gradle:不能排除两个log4j依赖关系之一?

标签 android android-studio gradle

发生错误
在尝试使用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/

相关文章:

android - 在android studio 3中保存 keystore 密码

java - Gradle JettyRun找不到MyBatis映射器xml文件

api - 如何在gradle中列出 “apply from”脚本

android - Admob 开始提供自己的奖励视频

Android Lint 不显示翻译缺失错误

Android Studio 无法识别源文件夹

java - Gradle中的WildFly Swarm + War + Local Jar依赖-NullPointerException

android - adb devices 不适用于 Mountain Lion

java - Java 中的扩展接口(interface)和转换错误

android - 在 Android Studio 中更改矢量 Assets 的填充颜色