Java編寫的代碼很容易被反編譯,但是可以使用proguard來盡最大努力來保護我們的代碼,proguard具體使用可以參考官方文檔(http://proguard.sourceforge.net/),現在就把我的配置寫下來(實際使用中),以供參考
1.到http://proguard.sourceforge.net/下載proguard
2.準備好要的jar包,我在這裡舉例是 Yulore_yellowSDK.jar
3.解壓proguard,雙擊 bin目錄下的proguardgui.bat,開啟Proguard圖形化視窗,如下圖所示:
Proguard 圖形化視窗:
選擇混淆設定檔proguard_common.cfg,如下:
選擇完成之後,點擊 Next,選擇 要混淆的jar檔案,如下:
點擊 Add input 按鈕,選擇 待混淆的jar檔案,如下:
同理,點擊 Add output 選擇混淆產生jar檔案的儲存路徑,如下:
完成之後,點擊 Next ,進入如下介面:
基本上不用修改,直接 點擊 Next 按鈕,進入下一個介面
不用修改,直接 點擊 Next
也不用做任何修改,直接點擊 Next
不用做任何修改,直接點擊 Next
來到這個介面,點擊Process 開始 代碼混淆,如下:
混淆完成後的介面,如下:
混淆設定檔 proguard_common.cfg
# 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 *;#}-dontshrink-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*-libraryjars D:/proguard_Test/proguard_libs/map.jar-libraryjars D:/proguard_Test/proguard_libs/core.jar-libraryjars D:/proguard_Test/proguard_libs/geocoder_location.jar-libraryjars D:/proguard_Test/proguard_libs/android.jar-libraryjars D:/proguard_Test/proguard_libs/annotations.jar-libraryjars D:/proguard_Test/proguard_libs/android-support-v4.jar-libraryjars D:/proguard_Test/proguard_libs/fastJson.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 * extends android.app.backup.BackupAgentHelper-keep public class * extends android.preference.Preference-keep public class com.android.vending.licensing.ILicensingService-keep public class * extends android.view.View-keep public class * extends android.app.Application-keep class com.yulore.yellowsdk.view.** { *; }-keep class com.yulore.yellowsdk.cache.** { *; }-keep class com.yulore.yellowsdk.entity.** { *; }-keep class com.yulore.yellowsdk.http.** { *; }-keep class com.yulore.yellowsdk.util.APIKeyFactory-keepclasseswithmembers class * { native <methods>;}-keepclasseswithmembers class * { public static <methods>;}-keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembers 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 *;}-dontwarn com.mapabc.mapapi.route.** -keep class com.mapabc.mapapi.map.** { *; }-keep class com.mapabc.mapapi.route.** { *; }-dontwarn android.support.v4.** -keep class android.support.v4.** { *; } -keep class android.support.v4.app.** { *; } -keep class android.support.v4.view.** { *; } -keep public class * extends android.support.v4.**-keepclassmembers class * { public <init>(org.json.JSONObject);}-keep class com.alibaba.fastjson.** { *; }
Proguard 根目錄:
依賴的jar包目錄:
混淆過程中有任何問題,可以參考以下網站:
http://docs.huihoo.com/proguard/manual/troubleshooting.html