proguard-rules.pro 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # 代码混淆压缩比,在0~7之间,默认为5,一般不做修改
  2. -optimizationpasses 5
  3. # 混合时不使用大小写混合,混合后的类名为小写
  4. -dontusemixedcaseclassnames
  5. # 指定不去忽略非公共库的类
  6. -dontskipnonpubliclibraryclasses
  7. # 这句话能够使我们的项目混淆后产生映射文件
  8. # 包含有类名->混淆后类名的映射关系
  9. -verbose
  10. # 指定不去忽略非公共库的类成员
  11. -dontskipnonpubliclibraryclassmembers
  12. # 不做预校验,preverify是proguard的四个步骤之一,Android不需要preverify,去掉这一步能够加快混淆速度。
  13. -dontpreverify
  14. # 保留Annotation不混淆
  15. -keepattributes *Annotation*,InnerClasses
  16. # 避免混淆泛型
  17. -keepattributes Signature
  18. # 抛出异常时保留代码行号
  19. #-keepattributes SourceFile,LineNumberTable
  20. # 指定混淆是采用的算法,后面的参数是一个过滤器
  21. # 这个过滤器是谷歌推荐的算法,一般不做更改
  22. -optimizations !code/simplification/cast,!field/*,!class/merging/*
  23. #-------------------------------------------------------默认保留区----------------------------------------------
  24. # 保留我们使用的四大组件,自定义的Application等等这些类不被混淆
  25. # 因为这些子类都有可能被外部调用
  26. -keep public class * extends android.app.Activity
  27. -keep public class * extends android.app.Application
  28. -keep public class * extends android.app.Service
  29. -keep public class * extends android.content.BroadcastReceiver
  30. -keep public class * extends android.content.ContentProvider
  31. -keep public class * extends android.app.backup.BackupAgentHelper
  32. -keep public class * extends android.preference.Preference
  33. -keep public class * extends android.view.View
  34. -keep public class * extends androidx.fragment.app.Fragment
  35. -keep public class * extends androidx.appcompat.app.AppCompatActivity
  36. -keep public class * extends androidx.viewbinding.ViewBinding {
  37. public static <methods>;
  38. }
  39. # 保留继承的
  40. -keep public class * extends android.support.v4.*
  41. -keep public class * extends android.support.v7.*
  42. -keep public class * extends android.support.annotation.*
  43. # 保留本地native方法不被混淆
  44. -keepclasseswithmembernames class * {
  45. native <methods>;
  46. }
  47. # 保留R下面的资源
  48. -keep class **.R$* {
  49. *;
  50. }
  51. # 保留在Activity中的方法参数是view的方法,
  52. # 这样以来我们在layout中写的onClick就不会被影响
  53. -keepclassmembers class * extends android.app.Activity{
  54. public void *(android.view.View);
  55. }
  56. # 保留枚举类不被混淆
  57. -keepclassmembers enum * {
  58. public static **[] values();
  59. public static ** valueOf(java.lang.String);
  60. }
  61. # 保留我们自定义控件(继承自View)不被混淆
  62. -keep public class * extends android.view.View{
  63. *** get*();
  64. void set*(***);
  65. public <init>(android.content.Context);
  66. public <init>(android.content.Context, android.util.AttributeSet);
  67. public <init>(android.content.Context, android.util.AttributeSet, int);
  68. }
  69. # 保留Parcelable序列化类不被混淆
  70. -keep class * implements android.os.Parcelable {
  71. *;
  72. }
  73. # 保留Serializable序列化的类不被混淆
  74. -keepclassmembers class * implements java.io.Serializable {
  75. static final long serialVersionUID;
  76. private static final java.io.ObjectStreamField[] serialPersistentFields;
  77. !static !transient <fields>;
  78. !private <fields>;
  79. !private <methods>;
  80. private void writeObject(java.io.ObjectOutputStream);
  81. private void readObject(java.io.ObjectInputStream);
  82. java.lang.Object writeReplace();
  83. java.lang.Object readResolve();
  84. }
  85. # 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
  86. -keepclassmembers class * {
  87. void *(**On*Event);
  88. void *(**On*Listener);
  89. }
  90. #WebView的处理
  91. -keepclassmembers class * extends android.webkit.WebViewClient {
  92. public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
  93. public boolean *(android.webkit.WebView, java.lang.String);
  94. }
  95. -keepclassmembers class * extends android.webkit.WebViewClient {
  96. public void *(android.webkit.WebView, java.lang.String);
  97. }
  98. # 移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用
  99. # 记得proguard-android.txt中一定不要加-dontoptimize才起作用
  100. # 另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制
  101. -assumenosideeffects class android.util.Log {
  102. public static int v(...);
  103. public static int i(...);
  104. public static int w(...);
  105. public static int d(...);
  106. public static int e(...);
  107. }
  108. #xutils
  109. -keepattributes Signature,*Annotation*
  110. -keep public class org.xutils.* {
  111. public protected *;
  112. }
  113. -keep public interface org.xutils.* {
  114. public protected *;
  115. }
  116. -keepclassmembers class * extends org.xutils.* {
  117. public protected *;
  118. }
  119. -keepclassmembers @org.xutils.db.annotation.* class * {*;}
  120. -keepclassmembers @org.xutils.http.annotation.* class * {*;}
  121. -keepclassmembers class * {
  122. @org.xutils.view.annotation.Event <methods>;
  123. }
  124. #BottomNavigationView
  125. -keep public class com.google.android.material.bottomnavigation.BottomNavigationView.* { *; }
  126. -keep public class com.google.android.material.bottomnavigation.BottomNavigationMenuView.* { *; }
  127. -keep public class com.google.android.material.bottomnavigation.BottomNavigationPresenter.* { *; }
  128. -keep public class com.google.android.material.bottomnavigation.BottomNavigationItemView.* { *; }
  129. #af
  130. -dontwarn com.android.installreferrer
  131. -dontwarn com.appsflyer.**
  132. -keep public class com.google.firebase.messaging.FirebaseMessagingService {
  133. public *;
  134. }
  135. -keep class com.google.android.gms.* { *; }
  136. -keep class com.huawei.hms.ads.* { *; }
  137. -keep interface com.huawei.hms.ads.* { *; }
  138. -dontwarn com.alibaba.fastjson.*
  139. -keep class com.alibaba.fastjson.*{*; }
  140. -keep class com.just.agentweb.*{*;}
  141. -dontwarn com.just.agentweb.*
  142. #-----------------------------------------------------特殊处理部分----------------------------------------------
  143. # AppCompat
  144. -keep class androidx.appcompat.** { *; }
  145. # ConstraintLayout
  146. -keep class androidx.constraintlayout.** { *; }
  147. # Legacy Support Library
  148. -keep class androidx.legacy.** { *; }
  149. # Material Components
  150. -keep class com.google.android.material.** { *; }
  151. # Navigation Component
  152. -keep class androidx.navigation.** { *; }
  153. # Lifecycle Extensions
  154. -keep class androidx.lifecycle.** { *; }
  155. # RecyclerView
  156. -keep class androidx.recyclerview.** { *; }
  157. # ButterKnife
  158. -keep class butterknife.** { *; }
  159. -dontwarn butterknife.internal.**
  160. -keep class **$$ViewBinder { *; }
  161. -keepclasseswithmembernames class * {
  162. @butterknife.* <methods>;
  163. }
  164. # Retrofit
  165. -keep class retrofit2.** { *; }
  166. -keepattributes Signature
  167. -keepattributes Exceptions
  168. # RxJava
  169. -keep class io.reactivex.** { *; }
  170. # CodeEditor
  171. -keep class com.ahmadaghazadeh.editor.** { *; }
  172. # Material Dialogs
  173. -keep class com.afollestad.materialdialogs.** { *; }
  174. # BaseRecyclerViewAdapterHelper
  175. -keep class com.chad.library.adapter.** { *; }
  176. # LiveEventBus
  177. -keep class com.jeremyliao.** { *; }
  178. # Room Persistence Library
  179. -keep class androidx.room.** { *; }
  180. -keepclassmembers class androidx.room.** {
  181. *;
  182. }
  183. # UtilCodeX
  184. -keep class com.blankj.utilcode.** { *; }
  185. # Work Manager
  186. -keep class androidx.work.** { *; }
  187. # XUtils
  188. -keep class org.xutils.** { *; }
  189. # Fastjson
  190. -keep class com.alibaba.fastjson.** { *; }
  191. # LogView
  192. -keep class com.sanyinchen.** { *; }
  193. # AppCenter
  194. -keep class com.microsoft.appcenter.** { *; }
  195. -keep class androidx.work.** { *; }
  196. -dontwarn com.jeremyliao.liveeventbus.**
  197. -keep class com.jeremyliao.liveeventbus.** { *; }
  198. -keep class androidx.lifecycle.** { *; }
  199. -keep class androidx.arch.core.** { *; }