I'm trying to build an android library project which uses OkHttp and Retrofit to grant access to our REST-backend.
It seems to be working as long as I use api
instead of implementation
on my gradle-dependency for com.squareup.retrofit2:converter-gson
. It seems that this is the only dependency needing this (all others can used with implementation
).
When using implementation
here as well, the calling app will crash with NoClassDefFoundError
:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/GsonBuilder;
I'm using consumerProguardFiles
with a bunch of proguard-rule-files (e.g. one for okhttp3, retrofit2 etc. from this repo). All this will then be packed into an AAR, so rules from the dependencies should be added as well.
It seems that I'm missing a proguard-rule for converter-gson
. Can somebody post the rules needed to use com.squareup.retrofit2:converter-gson
in a library project?
Edit 1
My current proguard-rule for retrofit is:
# Retrofit 2.X
## https://square.github.io/retrofit/ ##
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
As mentioned, this seems not enough. Maybe I need something else for converter-gson
!?
Edit 2
My dependencies look like this:
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
api "com.squareup.retrofit2:converter-gson:$retrofitVersion"
And I'm trying to get rid of the api
on the last one as I do not need it in the app using this library (or is this not avoidable)?
Edit 3
Hmm, maybe proguard is the wrong keyword. Actually the problem lies in the use of implementation
over api
. So dependencies will not be exposed to consumers. See https://stackoverflow.com/a/44493379/2170109.
But I don't get why I need to expose converter-gson
to consumers of my library when only the library calls GsonBuilder
?