d370urn3ur
d370urn3ur

Reputation: 1746

Android dependency conflict with jar embedded in aar

I am using an Android library project by importing the aar as an app module. The app compiles fine in debug mode but when I try to compile in release I get the following error :

Error: Program type already present: com.google.gson.DefaultDateTypeAdapter

So I dug around in my dependencies for gson and found out that the aar file has a bunch of embedded jar files included in it, and it seems to be conflicting with my external dependencies, notably Retrofit, OkHttp, and Gson

enter image description here

I have tried to exclude group com.google.code.gson when I import the aar module but no luck, it doesn't change anything:

implementation(project(':ONprintWS')) {
    exclude group: 'com.google.code.gson'
}

I also thought I could maybe remove the retrofit dependencies in my build.gradle, seeing as how they are included from the aar but when I do my classes can't find the retrofit / gson packages anymore.

I have asked the SDK maintainer to rebuild the SDK without the embedded jar (using transitive dependencies instead) but it might not happen for awhile, is there anyway to remove the embedded jars?

EDITED to show gradle excludes, still not working

//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation "com.google.code.gson:gson:2.8.5"
implementation("com.squareup.retrofit2:converter-gson:2.4.0") {
    exclude group: "com.google.code.gson"
}
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'

// ONprintWS SDK
implementation 'io.realm:realm-gradle-plugin:5.3.0'
implementation(project(':ONprintWS')) { // v1.0.4
    exclude group: "com.squareup.retrofit2"
    exclude group: "com.squareup.okhttp3"
    exclude group: "com.google.code.gson"
}

Upvotes: 0

Views: 1524

Answers (1)

Matthew Trout
Matthew Trout

Reputation: 741

One thing you can try instead of using exclude is to provide a resolutionStrategy for a given dependency, such as:

configurations.all { 
    resolutionStrategy { 
       force "com.android.support:support-v13:$SUPPORT_LIBRARY_VERSION" 
    } 
}

in the dependencies section. This will ensure a specific version is nominated for a given package

Upvotes: 1

Related Questions