Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProGuard not working with okhttp

Tags:

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.

like image 746
wkarl Avatar asked Dec 12 '14 12:12

wkarl


1 Answers

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

like image 51
pikufolgado Avatar answered Oct 09 '22 03:10

pikufolgado