Let's take a look at the following ideas:
Solve the problem that JSON cannot be parsed after gson Obfuscation
1. Do not confuse classes in the Google gson jar package
2. All attribute names in the object class implementing java. Io. serializable cannot be confused.
3. for serialization and deserialization, writeobject (); readobject (); writereplace (); readresolve (); cannot be confused.
Therefore, add
-Keep class com. Google .**{*;}
-Keepclassmembers class * implements java. Io. serializable {
Static final long serialversionuid;
Private Static final java. Io. objectstreamfield [] serialpersistentfields;
Private void writeobject (Java. Io. objectoutputstream );
Private void readobject (Java. Io. objectinputstream );
Java. Lang. Object writereplace ();
Java. Lang. Object readresolve ();
}
# ------------- 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
# Gson specific classes
-Keep class sun. Misc. Unsafe {*;}
#-Keep class com. Google. gson. Stream .**{*;}
# Application classes that will be serialized/deserialized over gson
-Keep class com. Google. gson. Examples. Android. model .**{*;}
# ------------- End: proguard configuration for gson ----------
The above code can be directly pasted in.