为了防止其他人盗用自己的源码,在发布apk之前我们可以对源码进行加密,防止反编译。
1、对工程添加proguard.cfg文件,自定义要混淆的文件类型。
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-libraryjars libs/android-support-v4.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 *;
}
-libraryjars 代表工程的lib引用
-keep 代表要保留的源码类型,不做混淆
-keepclasseswithmembernames 代表要保留的类,不做混淆
定义好proguard.cfg后,把proguard.cfg加到project.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=proguard.cfg*
# Project target.
target=android-21
android.library.reference.1=../../workspace/appcompat_v7
2、Eclipse中右键工程导出,添加已生成的keystore,或者新建keystore,加密导出。