|
19 | 19 | # If you keep the line number information, uncomment this to |
20 | 20 | # hide the original source file name. |
21 | 21 | #-renamesourcefileattribute SourceFile |
| 22 | + |
| 23 | +# 代码混淆压缩比,在0~7之间,默认为5,一般不做修改 |
| 24 | +-optimizationpasses 5 |
| 25 | + |
| 26 | +# 混合时不使用大小写混合,混合后的类名为小写 |
| 27 | +-dontusemixedcaseclassnames |
| 28 | + |
| 29 | +# 指定不去忽略非公共库的类 |
| 30 | +-dontskipnonpubliclibraryclasses |
| 31 | + |
| 32 | +# 这句话能够使我们的项目混淆后产生映射文件 |
| 33 | +# 包含有类名->混淆后类名的映射关系 |
| 34 | +-verbose |
| 35 | + |
| 36 | +# 指定不去忽略非公共库的类成员 |
| 37 | +-dontskipnonpubliclibraryclassmembers |
| 38 | + |
| 39 | +# 不做预校验,preverify是proguard的四个步骤之一,Android不需要preverify,去掉这一步能够加快混淆速度。 |
| 40 | +-dontpreverify |
| 41 | + |
| 42 | +# 保留Annotation不混淆 |
| 43 | +-keepattributes *Annotation*,InnerClasses |
| 44 | + |
| 45 | +# 避免混淆泛型 |
| 46 | +-keepattributes Signature |
| 47 | + |
| 48 | +# 抛出异常时保留代码行号 |
| 49 | +-keepattributes SourceFile,LineNumberTable |
| 50 | + |
| 51 | +# 指定混淆是采用的算法,后面的参数是一个过滤器 |
| 52 | +# 这个过滤器是谷歌推荐的算法,一般不做更改 |
| 53 | +-optimizations !code/simplification/cast,!field/*,!class/merging/* |
| 54 | + |
| 55 | +# apk 包内所有 class 的内部结构 |
| 56 | +#-dump class_files.txt |
| 57 | +# 未混淆的类和成员 |
| 58 | +-printseeds seeds.txt |
| 59 | +# 列出从 apk 中删除的代码 |
| 60 | +-printusage unused.txt |
| 61 | +# 混淆前后的映射 |
| 62 | +-printmapping mapping.txt |
| 63 | + |
| 64 | +############################################# |
| 65 | +# |
| 66 | +# Android开发中一些需要保留的公共部分 |
| 67 | +# |
| 68 | +############################################# |
| 69 | + |
| 70 | +# 保留我们使用的四大组件,自定义的Application等等这些类不被混淆 |
| 71 | +# 因为这些子类都有可能被外部调用 |
| 72 | +-keep public class * extends android.app.Activity |
| 73 | +-keep public class * extends android.app.Appliction |
| 74 | +-keep public class * extends android.app.Service |
| 75 | +-keep public class * extends android.content.BroadcastReceiver |
| 76 | +-keep public class * extends android.content.ContentProvider |
| 77 | +-keep public class * extends android.app.backup.BackupAgentHelper |
| 78 | +-keep public class * extends android.preference.Preference |
| 79 | +-keep public class * extends android.view.View |
| 80 | +-keep public class com.android.vending.licensing.ILicensingService |
| 81 | + |
| 82 | +-ignorewarnings -keep class * { public private *; } |
| 83 | + |
| 84 | +# 保留support下的所有类及其内部类 |
| 85 | +-keep class android.support.** { *; } |
| 86 | +-keep interface android.support.** { *; } |
| 87 | +-dontwarn android.support.** |
| 88 | + |
| 89 | +# 保留继承的 |
| 90 | +-keep public class * extends android.support.v4.** |
| 91 | +-keep public class * extends android.support.v7.** |
| 92 | +-keep public class * extends android.support.annotation.** |
| 93 | + |
| 94 | +# 保留R下面的资源 |
| 95 | +-keep class **.R$* {*;} |
| 96 | + |
| 97 | +# 保留本地native方法不被混淆 |
| 98 | +-keepclasseswithmembernames class * { |
| 99 | + native <methods>; |
| 100 | +} |
| 101 | + |
| 102 | +# 保留在Activity中的方法参数是view的方法, |
| 103 | +# 这样以来我们在layout中写的onClick就不会被影响 |
| 104 | +-keepclassmembers class * extends android.app.Activity{ |
| 105 | + public void *(android.view.View); |
| 106 | +} |
| 107 | + |
| 108 | +# 保留枚举类不被混淆 |
| 109 | +-keepclassmembers enum * { |
| 110 | + public static **[] values(); |
| 111 | + public static ** valueOf(java.lang.String); |
| 112 | +} |
| 113 | + |
| 114 | +# 保留我们自定义控件(继承自View)不被混淆 |
| 115 | +-keep public class * extends android.view.View{ |
| 116 | + *** get*(); |
| 117 | + void set*(***); |
| 118 | + public <init>(android.content.Context); |
| 119 | + public <init>(android.content.Context, android.util.AttributeSet); |
| 120 | + public <init>(android.content.Context, android.util.AttributeSet, int); |
| 121 | +} |
| 122 | + |
| 123 | +# 保留Parcelable序列化类不被混淆 |
| 124 | +-keep class * implements android.os.Parcelable { |
| 125 | + public static final android.os.Parcelable$Creator *; |
| 126 | +} |
| 127 | + |
| 128 | +# 保留Serializable序列化的类不被混淆 |
| 129 | +-keepnames class * implements java.io.Serializable |
| 130 | +-keepclassmembers class * implements java.io.Serializable { |
| 131 | + static final long serialVersionUID; |
| 132 | + private static final java.io.ObjectStreamField[] serialPersistentFields; |
| 133 | + !static !transient <fields>; |
| 134 | + !private <fields>; |
| 135 | + !private <methods>; |
| 136 | + private void writeObject(java.io.ObjectOutputStream); |
| 137 | + private void readObject(java.io.ObjectInputStream); |
| 138 | + java.lang.Object writeReplace(); |
| 139 | + java.lang.Object readResolve(); |
| 140 | +} |
| 141 | + |
| 142 | +# 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆 |
| 143 | +-keepclassmembers class * { |
| 144 | + void *(**On*Event); |
| 145 | + void *(**On*Listener); |
| 146 | +} |
| 147 | + |
| 148 | +# webView处理,项目中没有使用到webView忽略即可 |
| 149 | +-keepclassmembers class fqcn.of.javascript.interface.for.webview { |
| 150 | + public *; |
| 151 | +} |
| 152 | +-keepclassmembers class * extends android.webkit.webViewClient { |
| 153 | + public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); |
| 154 | + public boolean *(android.webkit.WebView, java.lang.String); |
| 155 | +} |
| 156 | +-keepclassmembers class * extends android.webkit.webViewClient { |
| 157 | + public void *(android.webkit.webView, jav.lang.String); |
| 158 | +} |
| 159 | + |
| 160 | +# 移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用 |
| 161 | +# 记得proguard-android.txt中一定不要加-dontoptimize才起作用 |
| 162 | +# 另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制 |
| 163 | +#-assumenosideeffects class android.util.Log { |
| 164 | +# public static int v(...); |
| 165 | +# public static int i(...); |
| 166 | +# public static int w(...); |
| 167 | +# public static int d(...); |
| 168 | +# public static int e(...); |
| 169 | +#} |
| 170 | + |
| 171 | +############################################# |
| 172 | +# |
| 173 | +# 项目中特殊处理部分 |
| 174 | +# |
| 175 | +############################################# |
| 176 | + |
| 177 | +# BottomNavigationMenuView |
| 178 | +-keepclassmembers class android.support.design.internal.BottomNavigationMenuView { |
| 179 | + boolean mShiftingMode; |
| 180 | +} |
| 181 | +# SearchView |
| 182 | +-keepclassmembers class android.support.v7.widget.SearchView { |
| 183 | + ImageView mGoButton; |
| 184 | +} |
| 185 | + |
| 186 | +#-----------处理反射类--------------- |
| 187 | + |
| 188 | + |
| 189 | +#-----------处理js交互--------------- |
| 190 | + |
| 191 | + |
| 192 | +#-----------处理实体类--------------- |
| 193 | +# 在开发的时候我们可以将所有的实体类放在一个包内,这样我们写一次混淆就行了。 |
| 194 | +#-keep class com.blankj.data.bean.**{ *; } |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +#-----------处理第三方依赖库--------- |
| 199 | + |
| 200 | +################ retrofit ############### |
| 201 | +-dontwarn retrofit2.** |
| 202 | +-keep class retrofit2.** { *; } |
| 203 | +-keepattributes Signature |
| 204 | +-keepattributes Exceptions |
| 205 | + |
| 206 | +################ gson ############### |
| 207 | +-keepattributes Signature |
| 208 | +-keepattributes *Annotation* |
| 209 | +-keep class sun.misc.Unsafe { *; } |
| 210 | +-keep class com.google.gson.stream.** { *; } |
| 211 | +# Application classes that will be serialized/deserialized over Gson |
| 212 | +-keep class com.sunloto.shandong.bean.** { *; } |
| 213 | + |
| 214 | +################ glide ############### |
| 215 | +-keep public class * implements com.bumptech.glide.module.AppGlideModule |
| 216 | +-keep public class * implements com.bumptech.glide.module.LibraryGlideModule |
| 217 | +-keep class com.bumptech.glide.** { *; } |
| 218 | +-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { |
| 219 | + **[] $VALUES; |
| 220 | + public *; |
| 221 | +} |
| 222 | + |
| 223 | +################ okhttp ############### |
| 224 | +-keepattributes Signature |
| 225 | +-keepattributes *Annotation* |
| 226 | +-keep class com.squareup.okhttp.** { *; } |
| 227 | +-keep interface com.squareup.okhttp.** { *; } |
| 228 | +-keep class okhttp3.** { *; } |
| 229 | +-keep interface okhttp3.** { *; } |
| 230 | +-dontwarn com.squareup.okhttp.** |
| 231 | + |
| 232 | +################ LitePal ############### |
| 233 | +-keep class org.litepal.** { |
| 234 | + *; |
| 235 | +} |
| 236 | +-keep class * extends org.litepal.crud.LitePalSupport{ |
| 237 | + *; |
| 238 | +} |
| 239 | + |
| 240 | +################ Bugly ############### |
| 241 | +-dontwarn com.tencent.bugly.** |
| 242 | +-keep public class com.tencent.bugly.**{*;} |
| 243 | +-keep class android.support.**{*;} |
| 244 | + |
| 245 | +################ autolayout ############### |
| 246 | +-keep class com.zhy.autolayout.** { *; } |
| 247 | +-keep interface com.zhy.autolayout.** { *; } |
| 248 | + |
| 249 | +################ RxJava and RxAndroid ############### |
| 250 | +-dontwarn org.mockito.** |
| 251 | +-dontwarn org.junit.** |
| 252 | +-dontwarn org.robolectric.** |
| 253 | + |
| 254 | +-keep class io.reactivex.** { *; } |
| 255 | +-keep interface io.reactivex.** { *; } |
| 256 | + |
| 257 | +-keepattributes Signature |
| 258 | +-keepattributes *Annotation* |
| 259 | +-keep class com.squareup.okhttp.** { *; } |
| 260 | +-dontwarn okio.** |
| 261 | +-keep interface com.squareup.okhttp.** { *; } |
| 262 | +-dontwarn com.squareup.okhttp.** |
| 263 | + |
| 264 | +-dontwarn io.reactivex.** |
| 265 | +-dontwarn retrofit.** |
| 266 | +-keep class retrofit.** { *; } |
| 267 | +-keepclasseswithmembers class * { |
| 268 | + @retrofit.http.* <methods>; |
| 269 | +} |
| 270 | + |
| 271 | +-keep class sun.misc.Unsafe { *; } |
| 272 | + |
| 273 | +-dontwarn java.lang.invoke.* |
| 274 | + |
| 275 | +-keep class io.reactivex.schedulers.Schedulers { |
| 276 | + public static <methods>; |
| 277 | +} |
| 278 | +-keep class io.reactivex.schedulers.ImmediateScheduler { |
| 279 | + public <methods>; |
| 280 | +} |
| 281 | +-keep class io.reactivex.schedulers.TestScheduler { |
| 282 | + public <methods>; |
| 283 | +} |
| 284 | +-keep class io.reactivex.schedulers.Schedulers { |
| 285 | + public static ** test(); |
| 286 | +} |
| 287 | +-keepclassmembers class io.reactivex.internal.util.unsafe.*ArrayQueue*Field* { |
| 288 | + long producerIndex; |
| 289 | + long consumerIndex; |
| 290 | +} |
| 291 | +-keepclassmembers class io.reactivex.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { |
| 292 | + long producerNode; |
| 293 | + long consumerNode; |
| 294 | +} |
| 295 | + |
| 296 | +-keepclassmembers class io.reactivex.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { |
| 297 | + io.reactivex.internal.util.atomic.LinkedQueueNode producerNode; |
| 298 | +} |
| 299 | +-keepclassmembers class io.reactivex.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { |
| 300 | + io.reactivex.internal.util.atomic.LinkedQueueNode consumerNode; |
| 301 | +} |
| 302 | + |
| 303 | +-dontwarn io.reactivex.internal.util.unsafe.** |
| 304 | + |
| 305 | +################ espresso ############### |
| 306 | +-keep class android.support.test.espresso.** { *; } |
| 307 | +-keep interface android.support.test.espresso.** { *; } |
| 308 | + |
| 309 | +################ annotation ############### |
| 310 | +-keep class android.support.annotation.** { *; } |
| 311 | +-keep interface android.support.annotation.** { *; } |
| 312 | + |
| 313 | +################ LeakCanary ################# |
| 314 | +-dontwarn com.squareup.haha.guava.** |
| 315 | +-dontwarn com.squareup.haha.perflib.** |
| 316 | +-dontwarn com.squareup.haha.trove.** |
| 317 | +-dontwarn com.squareup.leakcanary.** |
| 318 | +-keep class com.squareup.haha.** { *; } |
| 319 | +-keep class com.squareup.leakcanary.** { *; } |
| 320 | + |
| 321 | +################ AndroidAutoSize ################# |
| 322 | +-keep class me.jessyan.autosize.** { *; } |
| 323 | +-keep interface me.jessyan.autosize.** { *; } |
| 324 | + |
| 325 | +# Dagger2 |
| 326 | +-dontwarn com.google.errorprone.annotations.* |
| 327 | + |
| 328 | +# ButterKnife |
| 329 | +-keep public class * implements butterknife.Unbinder { |
| 330 | + public <init>(**, android.view.View); |
| 331 | +} |
| 332 | +-keep class butterknife.* |
| 333 | +-keepclasseswithmembernames class * { |
| 334 | + @butterknife.* <methods>; |
| 335 | +} |
| 336 | +-keepclasseswithmembernames class * { |
| 337 | + @butterknife.* <fields>; |
| 338 | +} |
| 339 | + |
| 340 | +# BRVAH |
| 341 | +-keep class com.chad.library.adapter.** { *; } |
| 342 | +-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter |
| 343 | +-keep public class * extends com.chad.library.adapter.base.BaseViewHolder |
| 344 | +-keepclassmembers public class * extends com.chad.library.adapter.base.BaseViewHolder { |
| 345 | + <init>(android.view.View); |
| 346 | +} |
| 347 | + |
| 348 | +# AndroidEventBus |
| 349 | +-keep class org.simple.** { *; } |
| 350 | +-keep interface org.simple.** { *; } |
| 351 | +-keepclassmembers class * { |
| 352 | + @org.simple.eventbus.Subscriber <methods>; |
| 353 | +} |
| 354 | + |
| 355 | +# ImmersionBar |
| 356 | +-keep class com.gyf.barlibrary.* {*;} |
| 357 | + -dontwarn com.gyf.barlibrary.** |
0 commit comments