ahmad aghazadeh ahmad aghazadeh - 1 year ago 69
Android Question

why Gson change property after release?

My class is :

private static class CameraSize {
public CameraSize(int h, int w) {
this.h = h;
this.w = w;

public int h;
public int w;

List<CameraSize> lstCS=new LinkedList<>();
Gson gson = new GsonBuilder().create();
for (int l = 0; l < listSize.size(); l++) {
int height = listSize.get(l).height;
int width = listSize.get(l).width;
CameraSize cs = new CameraSize(height, width);

Output in debug :


Output in release :


Why ??

Answer Source

In release mode, as you said in comments, you have minifyEnabled.

Names of your fields are changed after the obfuscation process. If you want to hold them without obfuscation, you have to tell Proguard to keep them.

You can keep all nested CameraSize classes:

-keep class **$CameraSize { *; }

Or only the specific one:

-keep class your.package.to.outer.class.OuterName$CameraSize { *; }

You can optimize it more specifying fields:

-keepclassmembers class your.package.to.outer.class.OuterName$CameraSize {
    public int h;    
    public int w;