Description: as a programmer who has been writing c # for a few years, the java level is not flattering. However, a task recently requires java code and obfuscation. Baidu has been experimenting with the Internet for a whole day, and it is finally a little achievement. When obfuscation occurs, the gson package is used, which leads to Code failure after obfuscation. After reading this article, I excerpted a section of configuration about gson settings, I am afraid to share it with others. The original article is reproduced.
Link: http://blog.csdn.net/sgwhp/article/details/9336695
When obfuscation of code containing SlidingMenu, the following error may be reported:
Can't find superclass or interface com. google. android. maps. MapActivity
...
If gson is used for serialization or deserialization of json, the program will throw NullPointerException because after the code is obfuscated, the member variables and the names of getter and setter have changed, in this way, the serialization is not normal.
Jni is the same.
The following is my use of proguard. cfg. If you encounter such errors, refer:
--repackageclasses --optimizations !code/simplification/-keepattributes *Annotation*---keep *-keep *-keep *-keep *-keep *-keep *-keep *-keep * <init> <init> <init>(android.content.Context, android.util.AttributeSet, *-keepclasseswithmembers * <init>-keepclasseswithmembers * <init>(android.content.Context, android.util.AttributeSet, -keepclassmembers * * *-keepclassmembers *-keepclassmembers **.R$* <fields> only a marker , so it wouldn-keepclassmembers * final -keepclasseswithmembernames *<methods>-keepclasseswithmembernames * <init>-keepclasseswithmembernames * <init>(android.content.Context, android.util.AttributeSet, -keepclassmembers **.R$* <fields> methods that are required -keepclassmembers * ** **-keep * *-keep * final android.os.Parcelable$Creator *---------------Begin: proguard configuration Gson ---------- a --keep sun.misc.Unsafe { *-keep com.google.gson.stream.** { *-keep com.google.gson.examples.android.model.** { *-keep com.google.gson.** { */-keep com.antew.redditinpictures.library.imgur.** { *-keep com.antew.redditinpictures.library.reddit.** { *---------------End: proguard configuration Gson -----------dontwarn android.support.**-dontwarn com.google.android.maps.**--keep android.support.** { *-keep com.actionbarsherlock.** { *-keep com.actionbarsherlock.** { *-keep com.slidingmenu.** { *-keep com.slidingmenu.** { *-keep org.hdstar.common.**{ *; }
Thanks to the author.