My problem is when running my app with release APK (proguard is enabled), GSON doesn't serialize my second object. First object is successfully serialized. But, app runs in debug mode everything is fine.
My app uses Retrofit2.6 and Proguard. Gradle version is gradle:3.5.1
My json data from WebServer
{
"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
}
]
}
And this is Response class for Retrofit
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;
}
}
This is my proguard rules
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-keepattributes *Annotation*
Publisher object is parsing when debug mode (proguard disabled). Publisher object is null when Release APK runs (proguard enabled).
I really research this problem very much. But i don't understand what is the problem is? Is there anyone who can help?
Edit: I kept all my model classes in Proguard rules for now but there's a mysterious mistake here. I can't find it. Why Channel object serialized but Publisher object didn't serialize?
Add this in your proguard
-keep public class com.package.name.models.** { *; }
Note:- com.package.name.models - this is your package name where your POJO class is located.
That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With