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

treesAreEverywhere :

In my Android project, I use a library that comes as a jar. I include it in the dependencies section like so:

dependencies {
    ...

    compile files('libs/thethirdpartylibrary.jar')
    ...
}

I also want to use the okhttp library, which I include like this:

compile ('com.squareup.okhttp:okhttp:2.7.5')

(This particular version of okhttp depends on okio 1.6.0.)

The problem is that the thirdparty jar library depends on okio v0.9.0 and what's worse, bundles it.

As a result, I get a dex conflict error at build time.

I was able to resolve this by manually removing okio from the jar file and this seems to work. But I'm wondering if there's a way to do this in gradle.

My question: Can I remove bundled, transitive ( <- I hope I'm using this word the right way) dependencies from an included jar during build-time with gradle?

Maheshwar Ligade :

Exclude the Group in the dependencies by using the below lines.

1.

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

2.

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

3.

configurations {
    runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}

Try this one.

For more detail

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Gradle build: Exclude resources files from Spring Boot Jar file

From Java

Gradle - Exclude file from being packaged with jar

From Java

How to exclude a jar from gradle

From Java

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

From Java

How to exclude dependencies from maven assembly plugin : jar-with-dependencies?

From Java

how to exclude gradle dependencies

From Java

How to exclude a jar from gradle

From

Using Gradle to build a jar with dependencies

From Dev

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

From Dev

Gradle: Exclude file from Android assets folder

From Dev

How to exclude dependencies in the POM file generated by the Gradle

From Dev

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

From Dev

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

From Dev

Gradle ear build with dependencies from war file

From Dev

Exclude Classes from Being Included in Shaded Jar

From Dev

Android - Gradle - How to download transitive dependencies for an included jar

From Dev

Build Gradle JAR without dependencies

From Dev

How to exclude library from all dependencies in Kotlin DSL build.gradle?

From Dev

How can I determine what dependencies I need in the gradle build file for my Android project

From Dev

How to build a gradle jar from a github library

From Dev

Gradle Dependencies aren't included in jar

From Dev

Gradle compile dependencies not included in Jar

From Dev

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

From Dev

Gradle KTS. How to move dependencies configuration to a separate file from main build?

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

How to exclude a dependency from built JAR in Gradle?

From Dev

Exclude class from jar with gradle

From Dev

Exclude Test folder and Resources from Gradle Jar build

From Dev

How to build jar library with dependencies with gradle?

Related Related

  1. 1

    Gradle build: Exclude resources files from Spring Boot Jar file

  2. 2

    Gradle - Exclude file from being packaged with jar

  3. 3

    How to exclude a jar from gradle

  4. 4

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

  5. 5

    How to exclude dependencies from maven assembly plugin : jar-with-dependencies?

  6. 6

    how to exclude gradle dependencies

  7. 7

    How to exclude a jar from gradle

  8. 8

    Using Gradle to build a jar with dependencies

  9. 9

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

  10. 10

    Gradle: Exclude file from Android assets folder

  11. 11

    How to exclude dependencies in the POM file generated by the Gradle

  12. 12

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

  13. 13

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

  14. 14

    Gradle ear build with dependencies from war file

  15. 15

    Exclude Classes from Being Included in Shaded Jar

  16. 16

    Android - Gradle - How to download transitive dependencies for an included jar

  17. 17

    Build Gradle JAR without dependencies

  18. 18

    How to exclude library from all dependencies in Kotlin DSL build.gradle?

  19. 19

    How can I determine what dependencies I need in the gradle build file for my Android project

  20. 20

    How to build a gradle jar from a github library

  21. 21

    Gradle Dependencies aren't included in jar

  22. 22

    Gradle compile dependencies not included in Jar

  23. 23

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

  24. 24

    Gradle KTS. How to move dependencies configuration to a separate file from main build?

  25. 25

    Maven - How to exclude dependencies from generated JAR

  26. 26

    How to exclude a dependency from built JAR in Gradle?

  27. 27

    Exclude class from jar with gradle

  28. 28

    Exclude Test folder and Resources from Gradle Jar build

  29. 29

    How to build jar library with dependencies with gradle?

HotTag

Archive