转载:混淆包含SlidingMenu、gson等Android代码的proguard写法
2014-03-21 08:55
239 查看
描述:作为一个写了几年c#的码农,咱的java水平实在不敢恭维,但是最近有个任务需要弄点java的代码,还要研究混淆。网上百度并实验了整整一天,终于算是有点成果了。其中混淆的时候由于用到了gson包,导致混淆后代码不能正常执行,看到了这篇文章,摘抄了其中关于gson设置的一段配置,就好了,不敢私藏分享一下。原文转载。
原文链接:http://blog.csdn.net/sgwhp/article/details/9336695
在混淆包含SlidingMenu的代码时,可能会报以下错误:
can't find superclass or interface com.google.android.maps.MapActivity
...
如果还使用到了gson来序列化或者反序列化json,程序还会抛出NullPointerException,这是因为代码被混淆后,成员变量以及getter、setter的名字都变了,这样就不能正常的序列化。
jni同理。
以下是本人使用的proguard.cfg,遇到此类错误的可以参考一下:
对作者便是感谢
原文链接:http://blog.csdn.net/sgwhp/article/details/9336695
在混淆包含SlidingMenu的代码时,可能会报以下错误:
can't find superclass or interface com.google.android.maps.MapActivity
...
如果还使用到了gson来序列化或者反序列化json,程序还会抛出NullPointerException,这是因为代码被混淆后,成员变量以及getter、setter的名字都变了,这样就不能正常的序列化。
jni同理。
以下是本人使用的proguard.cfg,遇到此类错误的可以参考一下:
-dontpreverify -repackageclasses '' -allowaccessmodification -optimizations !code/simplification/arithmetic -keepattributes *Annotation* -verbose -dontskipnonpubliclibraryclassmembers -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.support.v4.app.FragmentActivity -keep public class * extends android.support.v4.app.Fragment -keep public class * extends android.view.View { public <init>(android.content.Context); public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet, int); public void set*(...); } -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.content.Context { public void *(android.view.View); public void *(android.view.MenuItem); } -keepclassmembers class * implements android.os.Parcelable { static android.os.Parcelable$Creator CREATOR; } -keepclassmembers class **.R$* { public static <fields>; } # Explicitly preserve all serialization members. The Serializable interface # is only a marker interface, so it wouldn't save them. -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(); } # Preserve all native method names and the names of their classes. -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); } # Preserve static fields of inner classes of R classes that might be accessed # through introspection. -keepclassmembers class **.R$* { public static <fields>; } # Preserve the special static methods that are required in all enumeration classes. -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep public class * { public protected *; } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } ##---------------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.** { *; } -keep class com.google.gson.examples.android.model.** { *; } -keep class com.google.gson.** { *;} # Application classes that will be serialized/deserialized over Gson -keep class com.antew.redditinpictures.library.imgur.** { *; } -keep class com.antew.redditinpictures.library.reddit.** { *; } ##---------------End: proguard configuration for Gson ---------- -dontwarn android.support.** -dontwarn com.google.android.maps.** -dontwarn com.slidingmenu.lib.app.SlidingMapActivity -keep class android.support.** { *; } -keep class com.actionbarsherlock.** { *; } -keep interface com.actionbarsherlock.** { *; } -keep class com.slidingmenu.** { *; } -keep interface com.slidingmenu.** { *; } #所有实体类所在包 -keep class org.hdstar.common.**{ *; }
对作者便是感谢
相关文章推荐
- 混淆包含SlidingMenu、gson等Android代码的proguard写法
- Android项目proguard代码混淆遇到的一系列问题,外部jar,Gson包等
- Android项目proguard代码混淆遇到的一系列问题,外部jar,Gson包等
- Ant编译android,并Proguard代码混淆,v4混淆配置
- ANDROID使用PROGUARD实现代码混淆
- Android开发实践:利用ProGuard进行代码混淆
- Android 代码proguard混淆之后的错误log查看方法
- AndroidStudio proguard-rules.pro混淆 gson
- Android 代码混淆异常 transformClassesAndResourcesWithProguardForRelease FAILED
- Android中代码混淆之proguard
- 使用proguard混淆android代码
- ProguardGui进行jar包代码混淆(android library生成混淆jar包)
- Eclipse与Android源码中ProGuard工具的使用(代码混淆)
- Android 2.3 代码混淆proguard技术介绍
- Android用Proguard混淆代码ZZ
- proguard 混淆android代码
- 牛人必修 Ant编译android工程 ,并Proguard代码混淆,v4混淆配置
- Android杂谈--代码混淆及proguard一些错误处理
- android代码混淆之Gson解析为null
- Proguard android代码混淆 防止反编译