1 低版本SDK中,项目同时包含proguard.cfg和project.properties文件。在后者里面添加proguard.cfg = proguard.cfg,再将项目export即可。

在proguard.cfg中添加混淆规则就OK了,比如哪些不需要被混淆

2 高版本SDK中,同时包含proguard-project.txt和project.properties文件,在前者中进行下面配置即可,在export出来。Project.properties启用代码混淆,proguard-project.txt设置混淆规则,比如哪些必须要被混淆。和老版本的proguard.cfg规则一样

Prject.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 edit

“ant.properties”, and override values to adapt the script to your

project structure.

#

To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):

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

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

Project target.

target=android-16

proguiard-project.txt:

-optimizationpasses 5

-optimizations !code/simplification/arithmetic,!field/,!class/merging/

-dontoptimize

-dontpreverify

-dontusemixedcaseclassnames

-verbose

-dontskipnonpubliclibraryclasses

-dontskipnonpubliclibraryclassmembers

-overloadaggressively

#

Keep options for Android system

#

-keep public class * extends android.app.Activity{

public ;

public ;

}

-keep public class * extends android.app.Application

{

public ;

public ;

}

-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

-keepclassmembers enum * {

public static **[] values();

public static ** valueOf(java.lang.String);

}

-keepclasseswithmembers class * {

public (android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembers class * {

public (android.content.Context, android.util.AttributeSet, int);

}

-keepattributes Annotation

-keepclasseswithmembernames class *{

native ;

}

-keep class * implements android.os.Parcelable {

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

}

#

Keep options for your project

#