如果启用了Proguard,则retrofit2可以正常工作......但启用后,应用程序崩溃...
这是我的Proguard规则:
-dontwarn retrofit2.Platform$Java8
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations
-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
@retrofit2.* <methods>;
}
-keepclasseswithmembers interface * {
@retrofit2.* <methods>;
}
-keepclassmembers class demirci.omer.butun.gazeteler.siteler.newspapers.data.model.** { <fields>; }
-keep class demirci.omer.butun.gazeteler.siteler.newspapers.data.model.** { <fields>; }
-keep class demirci.omer.butun.gazeteler.siteler.newspapers.data.ApiEndPoint { <fields>; }
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class retrofit2.converter.gson.** { *; }
我已阅读以下问题: retrofit2 rule
但我也使用了POJO的retrofit2转换器。我觉得这个问题发生了......发现这个问题: gson-converter
出现问题的地方有两种情况。
Retrofit2 proguard规则不适合 或者,如果字段被混淆,则带有POJO的Retrofit2转换器GSON不会转换数据
我不知道出现哪种情况......
这是我的api界面:
public interface ApiEndPoint {
@FormUrlEncoded
@POST("all_newspaper/get_text.php")
Call<NewsContentClass> getContent(@Field("url") String url);
@FormUrlEncoded
@POST("all_newspaper/add_user_url.php")
Call<Void> addUserUrl(@Field("app_name") String appName,@Field("mobile_url") String mobile_url,@Field("desktop_url") String desktop_url);
}
答案 0 :(得分:0)
尝试添加
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
答案 1 :(得分:0)
从retrofit2网站尝试以下规则:
########--------Retrofit + RxJava--------#########
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions