Obfuscation of proguard writing that contains Android Code such as SlidingMenu and gson

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.