0

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"
}
d370urn3ur
  • 1,736
  • 4
  • 17
  • 24
  • removed my answer, because it makes no sense, that it complains either it cannot find GSON, and complains about it being duplicate when adding it once. file a support ticket at onprint.com – Martin Zeitler Oct 30 '18 at 01:17

1 Answers1

1

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

Matthew Trout
  • 709
  • 5
  • 20
  • To be honest, it doesn't feel like a simple dependency conflict problem... – Matthew Trout Oct 31 '18 at 15:38
  • I got the ONprint SDK maintainers to remove the embedded jars and now it works normally. So there was a dependency conflict with their embedded jars and my dependencies, but for the life of me I don't know why exclude and resolutionStrategy didn't work. It seems like gradle is not able to access jars embedded in aar packages. – d370urn3ur Nov 05 '18 at 10:18
  • Hmmm yes guess it could be that? Glad you got it sorted! – Matthew Trout Nov 05 '18 at 12:05