# 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 *; #} # 聲明第三方jar包 。 # 這裏本身看項目有什麼包就加什麼包,不要照搬。 -libraryjars libs/android-support-v4.jar -libraryjars libs/fastjson-1.1.43.android.jar -libraryjars libs/libammsdk.jar -libraryjars libs/open_sdk_r4889_lite.jar -libraryjars libs/umeng-analytics-v5.5.3.jar -libraryjars libs/umeng-update-v2.6.0.1.jar -libraryjars libs/com.umeng.message.lib_v2.3.0.jar -libraryjars libs/baidumapapi_v2_4_0.jar -libraryjars libs/locSDK_3.1.jar # 這裏是混淆後還能保留的屬性。 # 保留異常,內部類,註解,泛型,保留行號的屬性。 -keepattributes Exceptions,InnerClasses,*Annotation*,Signature,LineNumberTable # 還有其它屬性,如:LocalVariableTable 局部變量、SourceFile 源文件、Deprecated 廢棄、Synthetic 合成。 # 保留序列化。 # 好比咱們要向activity傳遞對象使用了Serializable接口的時候,這時候這個類及類裏面#的全部內容都不能混淆。 # 這裏若是項目有用到序列化和反序列化要加上這句。 -keepnames class * implements java.io.Serializable -keepclassmembers class * implements java.io.Serializable { *; } # 保留model,通常model最好避免混淆(model可有可無,不混淆也沒多大關係) # 這裏的com.oschina.test是本身項目的包名,不要照搬。 -keep class com.oschina.test.model.* {*;} # 保留適配器 -keep public class * extends android.widget.BaseAdapter {*;} # 若是你使用了CusorAdapter,添加下面這行 -keep public class * extends android.widget.CusorAdapter{*;} # 一樣若是你以爲麻煩,就直接將BaseAdpater換成Adapter # 保留資源類變量不被混淆,不然,你的反射是獲取不到資源id的 # 這裏的com.oschina.test是本身項目的包名,不要照搬。 -keep public class com.oschina.test.R$*{ public static final int *; } # 保留四大組件和自定義控件及組件。 # 若是咱們自定了ListView,ScrollView,Gallery這些組件的時候, # 咱們就不能混淆這些自定義的類了,由於在layout裏面咱們已經引用這個了類,並且已經寫死了。 # 第二句保留在activity中的方法參數是view的方法,這樣的話,咱們在xml裏面編寫onClick就不會被影響了 -keep public class * extends android.app.Activity -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } -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 * extends android.view.View {*;} -keep public class * extends android.app.Fragment -keep public class * extends android.support.v4.** -keep public class * extends android.support.v7.** -keep public class com.android.vending.licensing.ILicensingService -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int); } # 保留點擊和回調函數 -keepclasseswithmembers class * { void onClick*(...); } -keepclasseswithmembers class * { *** *Callback(...); } ##-----------------第三方jar包配置(選擇性添加)------------------------- # ImageLoader -dontwarn com.nostra13.universalimageloader.** -keep class com.nostra13.universalimageloader.** { *; } # 融雲 -dontwarn io.rong.** -keep class io.rong.** {*;} -keepclassmembers class **.R$* { public static <fields>; } -keep class *.R$ { *;} # 騰訊 -dontwarn com.tencent.** -keep class com.tencent.** { *;} # SlidingMenu -dontwarn com.jeremyfeinstein.slidingmenu.** -keep class com.jeremyfeinstein.slidingmenu.** { *; } # xutils -dontwarn com.lidroid.xutils.** -keep class com.lidroid.** { *; } -keep class * extends java.lang.annotation.Annotation { *; } # 友盟在線更新 -dontwarn com.umeng.** -keep public class * extends com.umeng.** -keep class com.umeng.** {*;} # 友盟推送 -keep class com.umeng.message.* { public <fields>; public <methods>; } -keep class com.umeng.message.protobuffer.* { public <fields>; public <methods>; } -keep class com.squareup.wire.* { public <fields>; public <methods>; } -keep class org.android.agoo.impl.*{ public <fields>; public <methods>; } -keep class org.android.agoo.service.* {*;} -keep class org.android.spdy.**{*;} # 新浪微博 -dontwarn com.sina.weibo.sdk.** -keep class com.sina.weibo.sdk.** { *; } # fastjson -dontwarn com.alibaba.fastjson.** -keep class com.alibaba.fastjson.** { *; } # pulltorefresh -dontwarn com.handmark.pulltorefresh.library.** -dontwarn com.handmark.pulltorefresh.library.extras.** -dontwarn com.handmark.pulltorefresh.library.internal.** -keep class com.handmark.pulltorefresh.library.** { *;} -keep class com.handmark.pulltorefresh.library.extras.** { *;} -keep class com.handmark.pulltorefresh.library.internal.** { *;} # 百度地圖 # 地圖組件包括圖層、定位等接口全部的類及類裏面的內容都不要混淆 # 交通實況相關的類及類裏面的全部內容不要混淆 -keep class com.baidu.** { *; } -keep class vi.com.gdi.bgl.android.**{*;} # android v4 v7擴展包 -dontwarn android.support.** -keep class android.support.v4.** { *; } -keep class android.support.v7.** { *; }
補充一下:javascript
對於引用第三方包的狀況,能夠採用下面方式避免打包出錯:html
-dontwarn com.xx.yy.** -keep class com.xx.yy.** { *;}