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?
Unfortunately, ProGuard can fail your build by emitting warnings at compile time when it detects problems with your code, such as referencing missing classes.
Make sure you are using the latest version. You should be able to work around the problem by using the -dontoptimize option. You can check the bug database to see if it is a known problem (often with a fix). Otherwise, please report it, preferably with the simplest example on which ProGuard fails.
For example, the method System.currentTimeMillis () returns a value, but it doesn't have any side effects. In the optimization step, ProGuard can then remove calls to such methods, if it can determine that the return values aren't used. ProGuard will analyze your program code to find such methods automatically.
This is a bit shady, since Android doesn't have this package at all, but if your application works anyway, you can let ProGuard accept it with " -dontwarn java.awt.** ", for instance. If the missing class is an Android run-time class, you should make sure that you are building against an Android run-time that is sufficiently recent.
-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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With