使用 Gradle 在 Android Studio 中从编译中排除 .jar [英] Exclude .jar from compile in Android Studio with Gradle

查看:30
本文介绍了使用 Gradle 在 Android Studio 中从编译中排除 .jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 build.gradle 文件中有类似的内容.

I currently have something like this in the build.gradle file.

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

    }
}

出现问题,因为 jUnit 和 hamcrest-core 都存在于 com.xxx:xxx maven 存储库中,从而产生如下错误:

A problem arises since both jUnit and hamcrest-core are present in the com.xxx:xxx maven repository, creating an error like this:

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(它没有被使用).

Since jUnit actually includes the hamcrest library these days is there a way to actually exclude the jar that is: hamcrest-core-1.3.jar Or exclude all .txt files, or exclude jUnit all together from the maven repository (it's not used).

还有其他有用的想法吗?

Any other ideas that could be helpful?

推荐答案

是的,你可以排除传递依赖:

在您的情况下,这将是:

In your case this would be:

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'
}

这篇关于使用 Gradle 在 Android Studio 中从编译中排除 .jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆