混淆的基本语法
-libraryjars class_path 应用的依赖包,如android-support-v4
-keep [,modifier,...] class_specification 不混淆某些类
-keepclassmembers [,modifier,...] class_specification 不混淆类的成员
-keepclasseswithmembers [,modifier,...] class_specification 不混淆类及其成员
-keepnames class_specification 不混淆类及其成员名
-keepclassmembernames class_specification 不混淆类的成员名
-keepclasseswithmembernames class_specification 不混淆类及其成员名
-assumenosideeffects class_specification 假设调用不产生任何影响,在proguard代码优化时会将该调用remove掉。如system.out.println和Log.v等等
-dontwarn [class_filter] 不提示warnning
常规不可混淆的代码
## ----------------------------------
## 常规规则
## ----------------------------------
-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 * extends android.view.View
1.腾讯系列SDK混淆
## ----------------------------------
## 腾讯统计sdk混淆
## ----------------------------------
-keep class com.tencent.stat.** {* ;}
-keep class com.tencent.mid.** {* ;}
## ----------------------------------
## 腾讯bugly sdk混淆
## ----------------------------------
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
## ----------------------------------
## 微信登录sdk
## ----------------------------------
-keep class com.tencent.mm.sdk.** {*;}
2.GSON混淆
## ----------------------------------
## Gson 相关的混淆配置
## ----------------------------------
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.** { *; }
-keep class com.google.gson.stream.** { *; }
3.ButterkKnife混淆
## ----------------------------------
## butterknife 相关的混淆配置
## ----------------------------------
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
4.EventBus混淆
## ----------------------------------
## EventBus 相关的混淆配置
## ----------------------------------
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
-keepclassmembers class ** {
public void onEvent*(**);
}
5.v4 包的混淆
## ----------------------------------
## v4 包的混淆
## ----------------------------------
#-libraryjars ./libs/android-support-v4.jar
#-dontwarn android.support.**
#-dontwarn android.support.v4.**
-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
6.universal-image-loader 混淆
## -------------------------------------------
## universal-image-loader 混淆
## -------------------------------------------
-dontwarn com.nostra13.universalimageloader.**
-keep class com.nostra13.universalimageloader.** { *; }
7.volley混淆
## -------------------------------------------
## volley混淆
## -------------------------------------------
-keep class com.android.volley.** {*;}
-keep class com.android.volley.toolbox.** {*;}
-keep class com.android.volley.Response$* { *; }
-keep class com.android.volley.Request$* { *; }
-keep class com.android.volley.RequestQueue$* { *; }
-keep class com.android.volley.toolbox.HurlStack$* { *; }
-keep class com.android.volley.toolbox.ImageLoader$* { *; }
8.高德地图sdk混淆
## ----------------------------------
## 高德地图sdk混淆
## ----------------------------------
# -libraryjars libs/android-support-v4.jar
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
#-libraryjars libs/AMap_2DMap_V2.8.1_20160202.jar
#-libraryjars libs/AMap_Location_v2.3.0_20160112.jar
#-libraryjars libs/AMap_Search_V2.8.0_20160105.jar
-dontwarn com.amap.api.**
-dontwarn com.a.a.**
-dontwarn com.autonavi.**
-keep class com.amap.api.** {*;}
-keep class com.autonavi.** {*;}
-keep class com.a.a.** {*;}
9.融云混淆
-keepattributes Exceptions,InnerClasses
-keepattributes Signature
-keep class io.rong.** {*;}
-keep class * implements io.rong.imlib.model.MessageContent {*;}
-dontwarn io.rong.push.**
-dontnote com.xiaomi.**
-dontnote com.google.android.gms.gcm.**
-dontnote io.rong.**
-ignorewarnings
-keep class com.evervc.ttt.push.RongPushMessageReceiver {*;}
10.个推混淆
## ----------------------------------
## 个推
## ----------------------------------
-dontwarn com.igexin.**
-keep class com.igexin.**{*;}
11.OrmLite混淆
#-libraryjars libs/ormlite-android-4.48.jar
#-libraryjars libs/ormlite-core-4.48.jar
-keep class com.j256.**{*;}
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**{*;}
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**{*;}
-keepclassmembers interface com.j256.** { *; }
12.不混淆org.apache.http.legacy.jar
-dontwarn android.net.compatibility.**
-dontwarn android.net.http.**
-dontwarn com.android.internal.http.multipart.**
-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-keep class android.net.compatibility.**{*;}
-keep class android.net.http.**{*;}
-keep class com.android.internal.http.multipart.**{*;}
-keep class org.apache.commons.**{*;}
-keep class org.apache.http.**{*;}
13.JS不混淆
-keepattributes Annotation
-keepattributes JavascriptInterface
-keep class android.webkit.JavascriptInterface {*;}
以上是第三方SDK混淆规则
我们代码中,还需要把自定义view、model类、自定义的类都摘出来,还有就是内部类
## ----------------------------------
## 自定义类不能混淆
## ----------------------------------
-keep class com.yao.test.utils.**{*;}
-keep class com.yao.test.service.**{*;}
-keep class com.yao.test.view.**{*;}
-keep class com.yao.test.net.**{*;}
## ----------------------------------
## model类混淆
## ----------------------------------
-keep class com.yao.test.model.** { *; }
#内部类不混淆
-keepnames class com.yao.test.controller.relation.MyRelationshipResultActivity$Rank{
public <fields>;
public <methods>;
}
网友评论