我的问题是,运行带有发行版APK(启用了防护)的应用程序时,GSON无法序列化我的第二个对象。第一个对象已成功序列化。但是,应用程序以调试模式运行,一切都很好。
我的应用程序使用Retrofit2.6和Proguard。 Gradle版本是gradle:3.5.1
我来自WebServer的json数据
{
"error": false,
"contents": [
{
"id": 1,
"channel": {
"id": 7,
"language_id": 1
},
"publisher": {
"id": 1,
"name": "Name of Publisher"
},
"title": "Some title",
"description": "This is description",
"subscribed": false
}
]
}
这是翻新的Response类
public class GetContentsResponse{
@SerializedName("error")
@Expose
private boolean mError;
@SerializedName("contents")
@Expose
private List<Content> mContents;
}
public class Content {
@SerializedName("id")
@Expose
private int mId;
@SerializedName("channel")
@Expose
private Channel mChannel;
@SerializedName("publisher")
@Expose
private Publisher mPublisher;
@SerializedName("title")
@Expose
private String mTitle;
@SerializedName("description")
@Expose
private String mDescription;
@SerializedName("subscribed")
@Expose
private boolean mSubscribed;
public int getId() {
return mId;
}
public Channel getChannel() {
return mChannel;
}
public String getTitle() {
return mTitle;
}
public String getDescription() {
return mDescription;
}
public boolean isSubscribed() {
return mSubscribed;
}
public Publisher getPublisher() {
return mPublisher;
}
}
这是我的保护人规则
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-keepattributes *Annotation*
在调试模式下(禁用了防护),正在解析Publisher对象。运行Release APK(启用了防护)时,Publisher对象为null。
我真的非常研究这个问题。但是我不明白问题是什么?有谁可以帮助您?
编辑:我现在将所有模型类都保留在Proguard规则中,但是这里有一个神秘的错误。我找不到为什么Channel对象已序列化而Publisher对象却未序列化?
答案 0 :(得分:0)
将此添加到您的proguard中
-keep public class com.package.name.models.** { *; }
注意:- com.package.name.models-这是POJO类所在的软件包名称。
就是这样。