Exclude a Module from an Android Library using Gradle

Recently I ran into a indirect dependency conflict issue while using an android library. The conflict message was:

Conflict with dependency ‘xmlpull:xmlpull’. Resolved versions for app (1.1.2.1) and test app (1.1.3.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

The root cause of the conflict was a CSV library that i was using. I added it as a gradle dependency in my project

dependencies {
    compile 'net.sf.jsefa:jsefa-android:1.1.0.RELEASE'
}

I built the dependency tree to figure out the source of conflict. Use this gradle command to check the dependencies.

./gradlew :app:dependencies

As you can see in the pictures below the conflict was between the version of xmlpull used by junit:junit:4.12 and my net.sf.jsefa:jsefa-android:1.1.0.RELEASE library.

JUnit Library which uses v1.1.3.1 of xmlpull:
JUnit Library

Jsefa Library which uses v1.1.2.1 of xmlpull:
Jsefa Library

One way to resolve this conflict is to force all modules to use a single version of a specific library.

configurations.all {
    resolutionStrategy { 
        force 'xmlpull:xmlpull:1.1.2.1'
    }
}

Forcing a particular configuration solves the version conflict issue. But one of the tasks while building the project failed.

:aapp:transformClassesAndResourcesWithProguardForPreKitkatProd

I got the following error in console.

Proguard issue

Basically xmlpull is included by default by jUnit. Other libraries should not include it as as a dependency and assume it would be provided by android. So the best solution is to make your library exclude building xmlpull

dependencies {
    compile ('net.sf.jsefa:jsefa-android:1.1.0.RELEASE') {
        exclude group: 'xmlpull'
    }
}

This addition of a line of code solves the problem which took almost my one whole day. 😀

This content has been helpful to you?

Thanks for contributing!

Yes No