简体   繁体   中英

How to exclude transitive jar dependency in Gradle?

My project depends on dependency A and dependency B.

Dependency A also depends on dependency B, but a different version of it.

The problem is in project A's build.gradle dependency B is included as a jar directly using the file and fileTree methods:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/B.jar')
}

My project's build.gradle looks like this:

dependencies {
    compile 'com.B:B:myvesion'
    compile('com.A:A:theirversion') {
        exclude module: 'B'
    }
}

But my build fails with this exception:

Execution failed for task ':myproject:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/B/someclass;

I want to exclude the jar version of B from my project and use my version. How do I do this? Seems like the exclude instruction doesn't work in my case.

You can't do it for the jar files.

You can exclude transitive dependencies (described in the pom file). The jar file is not a transitive dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM