代码混淆步骤:
1,project.properties中打开代码混淆功能,加入proguard.config=proguard.cfg
2,编辑proguard.cfg文件,项目没有自动生成时可手工新建并放到项目根目录,内容如下
-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -ignorewarnings -libraryjars libs/android-support-v4.jar -dontwarn android.support.v4.** -keep class android.support.v4.** { *; } -keep interface android.support.v4.app.** { *; } -keep public class * extends android.support.v4.** -keep public class * extends android.app.Fragment -libraryjars libs/asmack.jar -libraryjars libs/aws-android-sdk-1.7.1.1-core.jar -libraryjars libs/aws-android-sdk-1.7.1.1-s3.jar -libraryjars libs/LibFrameWidget.jar -libraryjars libs/LibFramework.jar -libraryjars libs/locSDK_4.0.jar -libraryjars libs/umeng_sdk.jar -libraryjars libs/zxing-core.jar -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 *; }
应该注意的地方如下:
1,android-support-v4.jar报错的话,要加上下面的代码
-ignorewarnings
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
2,所有Libs下的jar包都要加上引用说明,格式如下(*未对应的jar包名称)
-libraryjars libs/*.jar