GSON library problems on Android

1,550 views
Skip to first unread message

Joan Pujol

unread,
Nov 3, 2011, 9:48:52 AM11/3/11
to googl...@googlegroups.com
Hi,

I started to have problems with GSON library in some clients after starting enableComplexMapKeySerialization

I get a java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.enableComplexMapKeySerialization.
It's a very strange issue, because in only fails to a few users and the apk is the same for all.

Some one had this types of problems? Or knows if gson is integrated in some phone sdk and can make a version conflict using and older version that doesn't has enableComplexMapKeySerialization?

Any help will be greatly apreciated. A lot of thanks in advance,

Jesse Wilson

unread,
Nov 5, 2011, 9:14:14 AM11/5/11
to google-gson
Looks like it could be related to our HTC-shipping-Gson bug:
http://code.google.com/p/google-gson/issues/detail?id=255

The easiest workaround is to use jarjar to give Gson a different
package name when you distribute in an Android app.
http://code.google.com/p/jarjar/

Inderjeet Singh

unread,
Nov 5, 2011, 4:26:49 PM11/5/11
to googl...@googlegroups.com

Jane Wu

unread,
Apr 14, 2012, 11:21:23 AM4/14/12
to googl...@googlegroups.com
  i have tried your method on my proguard.cfg file 
but it seems that no use for my apps project 
and  below  is the  proguard file 


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

-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 * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

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

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

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



##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
this is my json class 

-keep class json.data.quickexpress.** { *; }

##---------------End: proguard configuration for Gson  ----------

can  you  help me ?thank u !


  
在 2011年11月6日星期日UTC+8上午4时26分49秒,Inderjeet Singh写道:

Ichigo Chan

unread,
Aug 11, 2013, 12:48:40 PM8/11/13
to googl...@googlegroups.com
Hi, I have copy everything from that proguard.cfg file but after obfuscating Gson returns a list of null objects. For more information, please check out my question.
I
s this some new problem with ProGuard or Gson or am I missing something? I think I really need to obfuscate my code so please help me find the solution.

Thank you.

Kasi Rajan M

unread,
Mar 31, 2014, 11:14:45 AM3/31/14
to googl...@googlegroups.com

I'm also experiencing a similar problem as you've mentioned. Anyhow, a temporary (not so obfuscated) solution to this problem is by adding the following to your proguard configuration:

-keep public class * {
public protected *;
}

Not sure if it is worth taking the risk of leaving your classes and their members names not obfuscated but at least it works with custom TypeAdapters.

Reply all
Reply to author
Forward
0 new messages