android代码混淆笔记

混淆处理的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选中project项目。右键菜单--> Android Tools

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

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

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

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

原文地址:https://www.cnblogs.com/zsychanpin/p/7168486.html