Android开发代码混淆经验(Eclipse)

为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤:

 

2、编辑项目下的proguard-project.txt,添加不需要混淆的规则(model、泛型、反射、第三方jar包),proguard-project.txt文件内容如下:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

#####################################
######### 主程序不能混淆的代码 #########
#####################################
######-dontwarn xxx.model.**
######-keep class xxx.model.** { *; }

#####################################
########### 不优化泛型和反射 ##########
#####################################
-keepattributes Signature
-keep class * extends java.lang.annotation.Annotation { *; }

#####################################
######### 不混淆第三方库或者jar包 #######
#####################################
-dontwarn net.sourceforge.jtds.**
-keep class net.sourceforge.jtds.** { *; }

-dontwarn com.iflytek.speech.**
-keep class com.iflytek.speech.** { *; }

-dontwarn com.lidroid.xutils.**
-keep class com.lidroid.xutils.** { *; }
#####################################

技巧:第三方jar包包名可以用WinRAR来打开jar文件,获取包路径。例如:jtds-1.2.jar,用WinRAR查看,可以发现包名为:net.sourceforge.jtds,所以只需要添加如下2行代码,即可不混淆该jar文件的相关包和类:

-dontwarn net.sourceforge.jtds.**
-keep class net.sourceforge.jtds.** { *; }



参考文章:
1、http://blog.csdn.net/lovexjyong/article/details/24652085
2、http://www.cnblogs.com/qianxudetianxia/p/4948499.html


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值