Exclude .jar from compile in Android Studio with Gradle

Joakim Engstrom

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.+') {

    }
}

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

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?

Sergii Pechenizkyi

Yes, you can exclude transitive dependencies:

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

or

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Exclude package from external JAR in Android Studio during Gradle build process

From Dev

In an Android Gradle build, how to exclude dependencies from an included jar file?

From Dev

How to exclude file from resources using Gradle and Android Studio?

From Dev

Android Studio - Gradle dependencies - How to Exclude `bolts` from `facebook`?

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Gradle: How to exclude a particular package from a jar?

From Dev

How to exclude modules or groups in a jar from Gradle?

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Android studio - How to use an executable jar file from gradle

From Dev

Gradle and Android Studio Duplicate File Copied from same jar

From Dev

Exclude BuildConfig.class and R.class from Android library jar in Gradle

From Dev

Android studio Gradle Could not find method compile()

From Dev

Android Studio Gradle Error at Compile Time

From Dev

Android Studio Gradle DSL method not found: 'compile()'

From Dev

Gradle: Exclude file from Android assets folder

From Dev

Gradle build: Exclude resources files from Spring Boot Jar file

From Dev

Android Studio can't compile, but gradle cli CAN compile

From Dev

Android Studio can't compile, but gradle cli CAN compile

From Dev

Android Gradle excluding jar from APK

From Dev

Gradle compile dependencies not included in Jar

From Dev

Gradle compile dependencies not included in Jar

From Dev

Android Studio gradle doesn't compile the specified version

From Dev

Android Studio RC 1 Gradle build wont compile after update

From Dev

Gradle Jar doesn't compile the .jar correctly?

From Dev

How to exclude a file from an .AAR Android library archive with gradle

From Dev

Imported jar in gradle, compiles, but not recognized by Android Studio (0.2.10)

From Dev

Android Studio with gradle built classes.jar is empty

From Dev

Android Studio using Git: gradle-wrapper.jar in version control

From Dev

Android Studio gradle sync, try to download jar instead of aar by mistake

Related Related

  1. 1

    Exclude package from external JAR in Android Studio during Gradle build process

  2. 2

    In an Android Gradle build, how to exclude dependencies from an included jar file?

  3. 3

    How to exclude file from resources using Gradle and Android Studio?

  4. 4

    Android Studio - Gradle dependencies - How to Exclude `bolts` from `facebook`?

  5. 5

    Gradle - Exclude file from being packaged with jar

  6. 6

    Gradle: How to exclude a particular package from a jar?

  7. 7

    How to exclude modules or groups in a jar from Gradle?

  8. 8

    Gradle - Exclude file from being packaged with jar

  9. 9

    Android studio - How to use an executable jar file from gradle

  10. 10

    Gradle and Android Studio Duplicate File Copied from same jar

  11. 11

    Exclude BuildConfig.class and R.class from Android library jar in Gradle

  12. 12

    Android studio Gradle Could not find method compile()

  13. 13

    Android Studio Gradle Error at Compile Time

  14. 14

    Android Studio Gradle DSL method not found: 'compile()'

  15. 15

    Gradle: Exclude file from Android assets folder

  16. 16

    Gradle build: Exclude resources files from Spring Boot Jar file

  17. 17

    Android Studio can't compile, but gradle cli CAN compile

  18. 18

    Android Studio can't compile, but gradle cli CAN compile

  19. 19

    Android Gradle excluding jar from APK

  20. 20

    Gradle compile dependencies not included in Jar

  21. 21

    Gradle compile dependencies not included in Jar

  22. 22

    Android Studio gradle doesn't compile the specified version

  23. 23

    Android Studio RC 1 Gradle build wont compile after update

  24. 24

    Gradle Jar doesn't compile the .jar correctly?

  25. 25

    How to exclude a file from an .AAR Android library archive with gradle

  26. 26

    Imported jar in gradle, compiles, but not recognized by Android Studio (0.2.10)

  27. 27

    Android Studio with gradle built classes.jar is empty

  28. 28

    Android Studio using Git: gradle-wrapper.jar in version control

  29. 29

    Android Studio gradle sync, try to download jar instead of aar by mistake

HotTag

Archive