从带有Gradle的Android Studio中的编译中排除.jar

时间:2013-11-19 12:31:10

标签: android maven gradle android-studio android-gradle

我目前在build.gradle文件中有这样的东西。

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile ('com.xxx:xxx-commons:1.+') {

    }
}

由于jUnit和hamcrest-core都存在于com.xxx:xxx maven存储库中,因此产生了一个问题,产生如下错误:

Gradle: Origin 1: /Users/yyy/.gradle/caches/artifacts-26/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar
Gradle: Origin 2: /Users/yyy/.gradle/caches/artifacts-26/filestore/org.hamcrest/hamcrest-core/1.3/jar/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar

Gradle: Execution failed for task ':android:packageDebug'.
> Duplicate files copied in APK LICENSE.txt
File 1: /Users/yyy/.gradle/caches/artifacts-26/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar
File 2: /Users/yyy/.gradle/caches/artifacts-26/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar

由于jUnit实际上包含了hamcrest库,这些天有一种实际排除jar的方法:hamcrest-core-1.3.jar 或者排除所有.txt文件,或者从maven存储库中排除jUnit(不使用它)。

任何其他可能有用的想法?

1 个答案:

答案 0 :(得分:14)

是的,你可以exclude transitive dependencies

在你的情况下,这将是:

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile ("com.xxx:xxx-commons:1.+") {
        exclude group: 'junit', module: 'junit'
    }
}

configurations {
    all*.exclude group: 'junit', module: 'junit'
}