ProGuard不能使用okhttp

ProGuard不会和okhttp一起玩,我不断收到以下警告:

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) 

这些是我okuptp和翻新的proguard设置:

 -dontwarn rx.** -dontwarn okio.** -dontwarn com.squareup.okhttp.* -dontwarn retrofit.appengine.UrlFetchClient -keep class retrofit.** { *; } -keepclasseswithmembers class * { @retrofit.http.* <methods>; } -keepattributes Signature -keepattributes *Annotation* 

这可能与Android Studio 1.0中对ProGuard的更改有关吗?

我尝试了相关问题的答案,但他们只build议使用我已有的设置。

Related of "ProGuard不能使用okhttp"

这适用于我:

你必须添加到你的proguard-rules.pro这两行:

 -keep class com.squareup.okhttp.** { *; } -keep interface com.squareup.okhttp.** { *; } 

完整的proguard-rules.pro文件将如下所示:

 -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* 

来源: https : //stackoverflow.com/a/24178851/4102045

我终于能够解决这个问题。

我遇到的警告实际上毫无意义,可以忽略。

相反,我忘了不模糊我的模型类:

 -keep class com.example.datamodel.** { *; } 

在这个改变后,一切正常。

它适用于我这个configuration。 所有使用封装子包的子类都使用**而不是*

 -dontwarn org.xmlpull.v1.** -dontwarn com.squareup.** -keep class com.squareup.** { *; } 

添加到你的proguard设置:

 -dontwarn com.squareup.okhttp.internal.huc.** 

我认为假设你没有使用com.squareup.okhttp.internal中的任何类是com.squareup.okhttp.internal因为这是你的警告源自的地方。

OkHttp

-keepattributes签名

-keepattributes 注释

维护类okhttp3。** {*; }

-keep接口okhttp3。** {*; }

-dontwarn okhttp3。**