Proguard不再适用于Retrofit

Nic*_*oso 13 android proguard retrofit

我发现较旧的问题涉及同一主题,但最新版本没有可用的答案适合我.

我在我的项目中使用Retrofit.当我尝试组装时,我收到以下错误:

警告:retrofit.client.OkClient:找不到引用的类com.squareup.okhttp.OkHttpClient

我正在使用以下内容,但它没有任何帮助:

-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.** { *; }
Run Code Online (Sandbox Code Playgroud)

最近有人有这个问题并解决了吗?

Yog*_*nan 47

-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.** { *; }
Run Code Online (Sandbox Code Playgroud)

我已经使用上面的proguard文本进行了使用OKHTTP的Retrofit.

编辑:很好的回购引用许多流行的图书馆 https://github.com/krschultz/android-proguard-snippets


Zac*_*ers 5

可能看似微不足道,但你试过包括这条线吗?(如果你不使用okhttp).

-dontwarn com.squareup.okhttp.**
Run Code Online (Sandbox Code Playgroud)

事情就是Square并没有在内部使用Proguard,所以虽然他们的库可能会对所使用的内容做出一些假设,但如果你的项目没有使用它,你可以放心地忽略它.我和毕加索有同样的问题,这为我解决了这个问题.