首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带Proguard的改装2

问带Proguard的改装2
EN

Stack Overflow用户
提问于 2016-06-15 07:23:45
回答 2查看 2.2K关注 0票数 1

如果不启用防护功能,retrofit2将正常工作...但一旦启用,应用程序就会崩溃...

以下是我的Proguard规则:

代码语言:javascript
复制
-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转换器。我认为问题出现在this...Found这个问题上:gson-converter

在哪里发生问题有两个条件。

如果字段被混淆,则Retrofit2保护规则不合适或带有POJO的Retrofit2转换器GSON不能转换数据

我不知道哪种情况会出现问题……

下面是我的api接口:

代码语言:javascript
复制
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);
}
EN

回答 2

Stack Overflow用户

发布于 2016-06-16 23:06:27

尝试添加

代码语言:javascript
复制
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
票数 0
EN

Stack Overflow用户

发布于 2017-08-23 15:58:03

从retrofit2站点尝试以下规则:

代码语言:javascript
复制
    ########--------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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37823729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档