1

如果没有启用 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);
}
4

2 回答 2

0

尝试添加

-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
于 2016-06-16T15:06:26.703 回答
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
于 2017-08-23T07:58:02.790 回答