2013年10月31日 星期四

Proguard 設定

目前版本:ADT R22

設定方法:
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: