2018/02/08

Android Proguard 範例

底下是我在某支程式中使用的範例,如果遇到一堆警告的話,通常是透過 -dontwarn 來解決,請見最後幾條。另外一種情況,最常見的解決方法就是用 -keep 來解決,請見前面幾條:

-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-verbose-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*


-keep public class * extends android.**
-keep public class * extends java.**
-keep public class com.android.vending.licensing.ILicensingService
-keep public class com.google.**

-keepclasseswithmembernames class * {
 native ;}

-keep public class * extends android.view.View {
 public (android.content.Context); public (android.content.Context, android.util.AttributeSet); public (android.content.Context, android.util.AttributeSet, int); public void set*(...);}

-keepclasseswithmembers class * {
 public (android.content.Context, android.util.AttributeSet);}

-keepclasseswithmembers class * {
 public (android.content.Context, android.util.AttributeSet, int);}

-keepclassmembers class * extends android.app.Activity {
 public void *(android.view.View);}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations-keepclassmembers enum * {
 public static **[] values(); public static ** valueOf(java.lang.String);}

-keep class * implements android.os.Parcelable {
 public static final android.os.Parcelable$Creator *;}

-keepclassmembers class **.R$* {
 public static ;}

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-dontwarn android.support.**
-dontwarn com.google.**
-dontwarn com.squareup.**