Using Gson in program that's being obfuscated by ProGuard

2510 views
Skip to first unread message

Rowno

unread,
Oct 27, 2010, 8:35:13 AM10/27/10
to google-gson
Hi, I'm currently working on an Android app that uses Gson to parse
JSON data that's returned from a server. It works fine, but when I
used ProGuard to obfuscate the app, Gson started returning null for
the List attribute in the object returned from Gson().fromJson(). Gson
isn't throwing any exceptions so I have no idea what's going wrong and
the rest of the app is working fine. Here's my ProGuard config file:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/
*


-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt

-keepattributes
SourceFile,LineNumberTable,Exceptions,Signature,Enclosing


-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context,
android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet,
int);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

Rowno

unread,
Oct 27, 2010, 7:40:43 PM10/27/10
to google-gson
I've resolved the problem. I realised that ProGuard was obfuscating
the field names of the classes passed to Gson().fromJson() which of
course stopped Gson from working. I added the following config option
to the ProGuard config file which fixed the problem by telling it not
to obfuscate the field names of those classes.

-keepclassmembers class fully.qualified.path.to.class$innerclass {
private <fields>;
}

PAWAN SHAHANI

unread,
Oct 9, 2018, 11:50:29 AM10/9/18
to google-gson
Hi...

As you said : -keepclassmembers class fully.qualified.path.to.class$innerclass { 
        private <fields>; 
}

I did : 

-keepclassmembers class com.hgs.ruralhealth_new.model.physiotherapist.PhysiotherapistResponse {
private String status, message, syncFromId, syncToId;
private List<PhysiotherapistInputData> data;
}

Is this correct ??
Reply all
Reply to author
Forward
0 new messages