標籤:
為了防止自己的勞動成果被別人竊取,混淆代碼能有效防止被反編譯,下面來總結以下混淆代碼的步驟:
2、編輯項目下的proguard-project.txt,添加不需要混淆的規則(model、泛型、反射、第三方jar包),proguard-project.txt檔案內容如下:
# To enable ProGuard in your project, edit project.properties# to define the proguard.config property as described in that file.## Add project specific ProGuard rules here.# By default, the flags in this file are appended to flags specified# in ${sdk.dir}/tools/proguard/proguard-android.txt# You can edit the include path and order by changing the ProGuard# include property in project.properties.## For more details, see# http://developer.android.com/guide/developing/tools/proguard.html# Add any project specific keep options here:# If your project uses WebView with JS, uncomment the following# and specify the fully qualified class name to the JavaScript interface# class:#-keepclassmembers class fqcn.of.javascript.interface.for.webview {# public *;#}############################################## 主程式不能混淆的代碼 ####################################################-dontwarn xxx.model.**######-keep class xxx.model.** { *; }################################################ 不最佳化泛型和反射 ###############################################-keepattributes Signature-keep class * extends java.lang.annotation.Annotation { *; }############################################## 不混淆第三方庫或者jar包 ############################################-dontwarn net.sourceforge.jtds.**-keep class net.sourceforge.jtds.** { *; }-dontwarn com.iflytek.speech.**-keep class com.iflytek.speech.** { *; }-dontwarn com.lidroid.xutils.**-keep class com.lidroid.xutils.** { *; }#####################################
技巧:第三方jar包包名可以用WinRAR來開啟jar檔案,擷取包路徑。例如:jtds-1.2.jar,用WinRAR查看,可以發現包名為:net.sourceforge.jtds,所以只需要添加如下2行代碼,即可不混淆該jar檔案的相關包和類:
-dontwarn net.sourceforge.jtds.**-keep class net.sourceforge.jtds.** { *; }
參考文章:
1、http://blog.csdn.net/lovexjyong/article/details/24652085
2、http://www.cnblogs.com/qianxudetianxia/p/4948499.html
Android開發代碼混淆經驗(Eclipse)