如果没有启用 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
但我也将 retrofit2 转换器与 POJO 一起使用。我认为这会出现问题......发现这个问题: 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);
}