Android proguard代码混淆

Google在2.3之后tools中就添加了自带的混淆器android-sdk-windows\tools\proguard

使用步骤如下:

一、在新建2.3项目的时候会自动生成proguard.cfg的文件

(如果你是2.3之前的版本,需要自己拷贝此文件到工程目录下)

文件中代码已经生成,如下:

-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 * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-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.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

二、在project.properties(default.properties)中添加一行命令,如下

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-9
proguard.config=proguard.cfg

三、重新生成apk

这里需要注意的是,如果只是clean后再bin下面生成的apk,会发现混淆没有起作用,还是和以前一样

这里我使用 右键点击工程->>Android Tools->>Export Signed Application Package..

上述步骤是对程序进行签名发布,在这时会对代码进行混淆。

如果混淆遇到错误,请首先检查你的工程路径是不是存在空格。

然后反编译出来就是a b c d之类的了

相关推荐