转载:混淆包含SlidingMenu、gson等Android代码的proguard写法
描述:作为一个写了几年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,遇到此类错误的可以参考一下:
-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写法的更多相关文章
- user模式下编译android 代码被proguard优化导致类和变量丢失
在Android项目中用到JNI,当用了proguard后,发现native方法找不到很多变量,原来是被produard优化掉了.所以,在JNI应用中该慎用progurad啊. 解决办法: 1.在An ...
- Android 代码混淆 混淆方案
本篇文章:自己在混淆的时候整理出比较全面的混淆方法,比较实用,自己走过的坑,淌出来的路.请大家不要再走回头路,可能只要我们代码加混淆,一点不对就会导致项目运行崩溃等后果,有许多人发现没有打包运行好好地 ...
- Android 代码混淆 防止反编译
为了防止代码被反编译,因此需要加入混淆.混淆也可以通过第三方进行apk混淆,也可以用android中的proguard进行混淆. 混淆步骤: 1.配置混淆文件,名字可以随意,在这里使用proguard ...
- Android 代码混淆
什么是代码混淆 Java 是一种跨平台的.解释型语言,Java 源代码编译成中间”字节码”存储于 class 文件中.由于跨平台的需要,Java 字节码中包括了很多源代码信息,如变量名.方法名,并且通 ...
- Android代码混淆和项目宣布步骤记录器
原本放在一起Android项目与发布的文件相混淆.我突然想到,为什么不写博客,分享.有这篇文章的情况下,. Android代码混淆及项目公布步骤记录 一.清理代码中的调试信息,如Log.System. ...
- android 代码混淆示例
参考其它资料为项目代码做了一下混淆 项目中使用了 slidingmenu actionbarsherlock fastjson volley httpclient 等第三方库, 并使用了 ...
- Android代码混淆及项目发布方法记录
Android代码混淆及项目发布步骤记录 本来整理了一份Android项目混淆与发布的文档,突然想到何不写篇博客,分享一下呢,如是便有了本文. Android代码混淆及项目发布步骤记录 一.清理 ...
- Android 代码混淆、Android Proguard(混淆)
Android Proguard(混淆) 混淆(Proguard)用法 最近项目中遇到一些混淆相关的问题,由于之前对proguard了解不多,所以每次都是面向Stackoverflow的编程.co ...
- Android 代码混淆规则
1. Proguard介绍 Android SDK自带了混淆工具Proguard.它位于SDK根目录toolsproguard下面.ProGuard是一个免费的Java类文件收缩,优化,混淆和预校验器 ...
随机推荐
- Windows7给C盘扩容
// 在之前的系统中都是使用PartitionMagic来进行磁盘容量的分配,但PartitionMagic在Windows7中的兼容性不是好很好,导致不能使用.其实Windows7自带了磁盘管理工具 ...
- AngularJS中实现日志服务
本篇体验使用AngularJS自定义一个记录日志的服务. 在AngularJS中,服务的一些写法是这样的: var app = angular.module('app',[]); app.provid ...
- 【译】在 Chrome 开发者工具中调试 node.js
原文链接 : Debugging Node.js in Chrome DevTools 原文作者 : MATT DESLAURIERS 译文出自 : 掘金翻译计划 译文链接 : https://git ...
- 【转】iOS设备的UDID是什么?苹果为什么拒绝获取iOS设备UDID的应用?如何替代UDID?
本文讲诉的主要是为什么苹果2011年8月发布iOS 5后就开始拒绝App获取设备的UDID以及UDID替补方案,特别提醒开发者苹果App Store禁止访问UDID的应用上架(相关推荐:APP被苹果A ...
- 适合wordpress中文网站的seo优化插件 DX-Seo
DX-Seo是一款强大的多功能wordpress seo插件,主要功能及其使用方法如下 全局开关设置 启动插件后,进入"DX-Seo"栏目,你可以开启或者关闭其中的所有功能. 自动 ...
- chrome start.js报错
是由 chrome 插件 “电脑管家广告过滤” 引起的 并且,在用户电脑上还出现了这个插件拦截正常请求的情况 如果同时报以下错误: Uncaught TypeError: Cannot read pr ...
- 【C#】取得并改变图像解析度
, , bmpOrg.Width, bmpOrg.Height); g.Dispose(); // 画像を保存 string dirName = Path.GetD ...
- 查看iOS模拟器应用的沙箱文件
iOS 升级到8.3 以后就不能用iFunBox 这样的工具看沙箱里的文件了(非共享的), 而开发时我们的数据库文件又不在共享目录里.关于这个问题,我们可以看模拟器里的沙箱文件, iOS8.0 以后, ...
- mac添加环境变量
两个问题: 1.nodejs的安装 使用Mac OS X Binaries (.tar.gz)(64位)来安装: http://www.nodejs.org/download/ 安装参照:http:/ ...
- easyui plugin——etreegrid:CRUD Treegrid
昨天写了一个ko+easyui的同样的实现,感觉写的太乱,用起来十分麻烦,于是今天照着edatagrid,写了一个etreegrid,这样再用ko绑定就方便多了. 使用很简单,$(tableId).e ...