Reputation: 809
ProGuard won't play nice with okhttp and I keep getting the following Warnings:
Warning:com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning:com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning:com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning:com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning:there were 4 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
These are my proguard settings for okhttp and retrofit:
-dontwarn rx.**
-dontwarn okio.**
-dontwarn com.squareup.okhttp.*
-dontwarn retrofit.appengine.UrlFetchClient
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>; }
-keepattributes Signature
-keepattributes *Annotation*
Could this have something to do with the changes to ProGuard in Android Studio 1.0?
I tried the answers to related questions but they only suggested to use the settings I already have.
Upvotes: 26
Views: 22864
Reputation: 499
okhttp3 Proguard Rules
Here is the correct format for okhttp3 Proguard.
-keepattributes Signature
-keepattributes Annotation
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
Upvotes: -1
Reputation: 302
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
Upvotes: 1
Reputation: 38267
For okhttp3, you need the following:
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
Upvotes: 1
Reputation: 474
In case somebody still falls into here. The required Proguard configuration is documented and maintained on the main OkHttp repository:
https://github.com/square/okhttp
Upvotes: 1
Reputation:
-keepattributes Signature
-keepattributes Annotation
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
Upvotes: 7
Reputation: 809
I was finally able to solve this problem.
The warnings I encountered were actually meaningless and can be ignored.
Instead I forgot to not obfuscate my model classes:
-keep class com.example.datamodel.** { *; }
After this change everything worked fine.
Upvotes: 14
Reputation: 2121
Add this to your proguard settings:
-dontwarn com.squareup.okhttp.internal.huc.**
I think it's safe to assume that you're not using any of the classes in com.squareup.okhttp.internal
since that's where your warnings are originating from.
Upvotes: 1
Reputation: 373
This works for me:
You have to add to your proguard-rules.pro this two lines:
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
Complete proguard-rules.pro file will look like:
-dontwarn rx.**
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn retrofit.**
-dontwarn retrofit.appengine.UrlFetchClient
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
-keepattributes Signature
-keepattributes *Annotation*
Source: https://stackoverflow.com/a/24178851/4102045
Upvotes: 37
Reputation: 9429
it works for me with this configs. use **
instead of *
for all sub classes with encapsulated child packages
-dontwarn org.xmlpull.v1.**
-dontwarn com.squareup.**
-keep class com.squareup.** { *; }
Upvotes: 1