【问题标题】:Retrofit 2 with Proguard使用 Proguard 改造 2
【发布时间】:2016-06-14 23:23:44
【问题描述】:

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

【问题讨论】:

    标签: retrofit2 jsonschema2pojo


    【解决方案1】:

    尝试添加

    -keepclasseswithmembers class * {
        @retrofit2.http.* <methods>;
    }
    

    【讨论】:

      【解决方案2】:

      从 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-04-29
        • 1970-01-01
        • 1970-01-01
        • 2016-06-01
        • 1970-01-01
        • 2017-10-27
        • 2015-12-25
        • 2017-11-12
        • 1970-01-01
        相关资源
        最近更新 更多