【问题标题】:Exclude .jar from compile in Android Studio with Gradle使用 Gradle 在 Android Studio 中从编译中排除 .jar
【发布时间】:2013-12-03 00:18:50
【问题描述】:

我目前在 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 文件,或者将 jUnit 全部从 maven 存储库中排除(未使用)。

还有其他有用的想法吗?

【问题讨论】:

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


    【解决方案1】:

    是的,你可以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'
    }
    

    【讨论】:

    • 这对我有用,只是略有改动。我不得不离开这个小组。所以我的排除行看起来像这样:exclude module: 'support-v4'
    • 什么版本的gradle和android gradle wrapper提供了“排除”功能?
    • @DanielBaughman 我相信您面临的问题是:stackoverflow.com/questions/23172458/…
    • @AbrahamPhilip 我相信你是对的。我认为就我而言,我需要使用后一种语法,并且我一直在尝试使用前者。
    • 是否有任何正确的解决方案。我遇到了同样的问题 java.util.zip.ZipException:重复条目:com/google/gson/annotations/Expose.class 请帮助我。我把这样的配置{ all*.exclude module: 'gson-2.1' }
    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 2019-04-23
    • 2015-04-26
    • 2014-06-20
    相关资源
    最近更新 更多