Pregunta

I have found older questions which touch on the same subject but with the latest versions none of the available answers work for me.

I am using Retrofit in my project. When I try to assemble I get the following error:

Warning: retrofit.client.OkClient: can't find referenced class com.squareup.okhttp.OkHttpClient

I'm using the following but none of it is helping:

-keepattributes Signature

-keep class retrofit.** { *; }
-keep class retrofit.http.** { *; }
-keep class retrofit.client.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class com.google.gson.** { *; }
-keep class com.google.inject.* { *; }
-keep class org.apache.http.* { *; }
-keep class org.codehaus.mojo.** { *; }
-keep class org.apache.james.mime4j.* { *; }
-keep class javax.inject.* { *; }
-keep class sun.misc.Unsafe { *; }

-libraryjars libs/acra-4.5.0.jar
-libraryjars libs/radial-menu-v4.jar

-dontwarn javax.xml.stream.events.**
-dontwarn rx.**
-dontwarn org.apache.lang.**

# Application classes that will be serialized/deserialized over Gson
-keep class com.example.package.network.** { *; }

Has anybody had this issue recently and resolved it?

¿Fue útil?

Solución 2

Might seem trivial, but have you tried including this line? (If you don't use okhttp that is).

-dontwarn com.squareup.okhttp.**

Thing is Square doesn't use Proguard internally, so while their libraries may make some assumptions of what's being used, you can safely ignore it if your project doesn't use it. I had the same issue with Picasso and this fixed it for me.

Otros consejos

-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**

-dontwarn rx.**
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

-keep class sun.misc.Unsafe { *; }
#your package path where your gson models are stored  
-keep class com.example.models.** { *; }

I have used the above proguard text for Retrofit with OKHTTP.

EDIT: Nice repo to refer for many popular libraries https://github.com/krschultz/android-proguard-snippets

This configuration worked for retrofit with gson.

#Using for retrofit & gson
-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.* { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; }
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keepclassmembernames interface * {
    @retrofit.http.* <methods>;
}
-keep interface retrofit.** { *;}
-keep interface com.squareup.** { *; }
-dontwarn rx.**
-dontwarn retrofit.**

plus you need to add all the POJO classes which is used with retrofit just like below.

-keep class com.google.gson.examples.android.model.** { *; }
-keep class com.packagename.your.pojo.models.** { *; }

keepattributes like below

-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes Deprecated
-keepattributes SourceFile
-keepattributes LineNumberTable
-keepattributes *Annotation*
-keepattributes EnclosingMethod

A nice discussion about proguard with retrofit goes here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top