設定方法:
1.打開project.properties, 把下面這行註解拿掉.
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
proguard-android.txt可以換成proguard-android-optimize.txt
2.在proguard-project.txt加入要設定的內容,範例如下
# for debug
#-renamesourcefileattribute SourceFile
#-keepattributes SourceFile,LineNumberTable
-dontskipnonpubliclibraryclassmembers
-dontpreverify
#-dontshrink
-libraryjars ./libs/android-support-v4.jar
-libraryjars ./libs/gson-2.2.2.jar
-libraryjars ./libs/YouTubeAndroidPlayerApi.jar
-dontwarn org.apache.**
-dontwarn org.w3c.**
-dontwarn org.json.*
-dontwarn com.google.**
-dontwarn javax.**
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class com.google.** { *; }
# 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 *;
}
-keepclasseswithmembernames class * {
native ;
}
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.shaw.app.bean.** { *; }
##---------------End: proguard configuration for Gson ----------
3.測試 & debug. 必須全部重測一遍, 確保所有功能都正常.
4.Release!
Reference:
http://stackoverflow.com/questions/10209404/obfuscated-code
http://developer.android.com/tools/help/proguard.html
http://proguard.sourceforge.net/
http://blog.cuelogic.co.in/how-to-use-proguard-in-android/
http://stackoverflow.com/questions/5068251/android-what-are-the-recommended-configurations-for-proguard
http://stackoverflow.com/questions/14501759/proguard-errors-with-external-jar-returns-error-code-1
http://www.haogongju.net/art/2312944
http://blog.csdn.net/zengyangtech/article/details/6127600
http://stackoverflow.com/questions/16563916/proguard-issue-while-using-gson