android代码混淆笔记

来源:互联网 发布:香港记者知乎 编辑:程序博客网 时间:2024/06/03 16:08

混淆处理的apk被反编译后代码中包名类名等都变成abcd之类,很难看懂。

使用代码混淆,启用混淆器,对相关文件进行编辑,然后打包签名就可以了;

------------

在2.3的版本中,项目中有这个文件 proguard.cfg   (没有的可以手动添加)

           添加一句:  proguard.config=proguard.cfg

proguard.cfg文件中内容:   

-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*-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 com.android.vending.licensing.ILicensingService-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);}-keepclassmembers enum * {    public static **[] values();    public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable {  public static final android.os.Parcelable$Creator *;}

-------------------------

在4.0以后的版本,项目中的文件是project.properties和proguard-project.txt。

 

打开project.properties,取消下面这行代码的注释:

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

默认的设置是不带优化功能的,可以用以下设置加上代码优化功能:
#proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

 

-------------------------------------------------------

proguard-project.txt 文件的一些编辑规则:

-libraryjars libs/android-support-v4.jar

-libraryjars libs      加载第三方Jar包

-ignorewarnings      去除代码中的警告


-keep class com.xxx.xxx.**

-keep 保留不混淆的类

 此类的公共方法保留,不混淆。
-keep class com.xx.xx.Test{
public *;
}

保护指定的类文件和类的成员

-keep class * implements android.os.Parcelable {

public static final android.os.Parcelable$Creator *;
}


----------------------------------------------------

 

用Eclipse工具打包签名:

在Eclipse选中工程项目,右键菜单--> Android Tools

                ---> Export Signed Application Package...带RSA数字签名

                ---> Export Unsigned Application Package...不带数字签名

选择一种方式按照向导操作,生成的Apk就是混淆处理过的。

----------------------------------------

0 0
原创粉丝点击