混淆處理的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 ; } -keepclasseswithmembernames class * { public (android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public (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選中工程項目,右鍵菜單–> Android Tools
—> Export Signed Application Package…帶RSA數字簽名
—> Export Unsigned Application Package…不帶數字簽名
選擇一種方式按照向導操作,生成的Apk就是混淆處理過的。
—————————————-