proguard-rules.pro 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #####################################################
  2. # 基本配置 #
  3. #####################################################
  4. # 指定代码的压缩级别 0 - 7
  5. -optimizationpasses 5
  6. # 不使用大小写混合类名
  7. -dontusemixedcaseclassnames
  8. # 如果应用程序引入的有jar包,并且想混淆jar包里面的class
  9. -dontskipnonpubliclibraryclasses
  10. # 混淆时是否做预校验(可去掉加快混淆速度)
  11. -dontpreverify
  12. #-dontoptimize
  13. # 混淆时是否记录日志(混淆后生产映射文件 map 类名 -> 转化后类名的映射
  14. -verbose
  15. # 淆采用的算法
  16. -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
  17. #指定外部模糊字典
  18. -obfuscationdictionary ./dictionary/proguard-1il.txt
  19. #指定class模糊字典
  20. -classobfuscationdictionary ./dictionary/proguard-o0O.txt
  21. #指定package模糊字典
  22. -packageobfuscationdictionary ./dictionary/proguard-socialism.txt
  23. # 所有 Android 控件的子类不要去混淆
  24. -keep public class * extends android.app.Activity
  25. -keep public class * extends android.app.Application
  26. -keep public class * extends android.app.Service
  27. -keep public class * extends android.content.BroadcastReceiver
  28. -keep public class * extends android.content.ContentProvider
  29. -keep public class * extends android.app.backup.BackupAgentHelper
  30. -keep public class * extends android.preference.Preference
  31. # 所有 Android 支持库子类不混淆
  32. -keep public class * extends com.support.**
  33. -keep public class * extends androidx.**
  34. -dontwarn javax.lang.model.element.Element
  35. # 保持 native 的方法不去混淆
  36. -keepclasseswithmembernames class * {
  37. native <methods>;
  38. }
  39. # 保持自定义控件类不被混淆,指定格式的构造方法不去混淆
  40. -keepclasseswithmembers class * {
  41. public <init>(android.content.Context, android.util.AttributeSet);
  42. }
  43. -keepclasseswithmembers class * {
  44. public <init>(android.content.Context, android.util.AttributeSet, int);
  45. }
  46. # Android layout 布局文件中为控件配置的onClick方法不能混淆
  47. -keepclassmembers class * extends android.app.Activity {
  48. public void *(android.view.View);
  49. }
  50. # 保持自定义控件指定规则的方法不被混淆
  51. -keep public class * extends android.view.View {
  52. public <init>(android.content.Context);
  53. public <init>(android.content.Context, android.util.AttributeSet);
  54. public <init>(android.content.Context, android.util.AttributeSet, int);
  55. public void set*(...);
  56. }
  57. # 保持枚举 enum 不被混淆
  58. -keepclassmembers enum * {
  59. public static **[] values();
  60. public static ** valueOf(java.lang.String);
  61. }
  62. # 保持 Parcelable 不被混淆(aidl文件不能去混淆)
  63. -keep class * implements android.os.Parcelable {
  64. public static final android.os.Parcelable$Creator *;
  65. }
  66. # 需要序列化和反序列化的类不能被混淆(注:Java反射用到的类也不能被混淆)
  67. -keepnames class * implements java.io.Serializable
  68. # 保护实现接口Serializable的类中,指定规则的类成员不被混淆
  69. -keepclassmembers class * implements java.io.Serializable {
  70. static final long serialVersionUID;
  71. private static final java.io.ObjectStreamField[] serialPersistentFields;
  72. !static !transient <fields>;
  73. private void writeObject(java.io.ObjectOutputStream);
  74. private void readObject(java.io.ObjectInputStream);
  75. java.lang.Object writeReplace();
  76. java.lang.Object readResolve();
  77. }
  78. # 过滤泛型(不写可能会出现类型转换错误,一般情况把这个加上就是了)
  79. -keepattributes Signature
  80. # 假如项目中有用到注解,应加入这行配置
  81. -keepattributes *Annotation*
  82. # 保持 R 文件不被混淆,否则,你的反射是获取不到资源id的
  83. -keep class **.R$* { *; }
  84. # 保持ViewModel和ViewBinding不混淆,否则无法反射自动创建
  85. -keep class * implements androidx.viewbinding.ViewBinding { *; }
  86. -keep class * extends androidx.lifecycle.ViewModel { *; }
  87. #####################################################
  88. # 自定义配置 #
  89. #####################################################
  90. # 保护 WebView 对 HTML 页面的API不被混淆
  91. -keep class **.WebView2JsInterface { *; }
  92. # 数据 Entity 类
  93. ######
  94. -keep class vn.hongyegroup.yybusiness.entity.** { *; }
  95. -keep class com.android.basiclib.bean.** { *; }
  96. # Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
  97. -dontwarn kotlin.Unit
  98. -keep class androidx.lifecycle.** { *; }
  99. -keep class androidx.arch.core.** { *; }
  100. # kotlin serialization
  101. -keepattributes *Annotation*, InnerClasses
  102. -keepclassmembers class kotlinx.serialization.json.** {
  103. *** Companion;
  104. }
  105. #Android X 混淆
  106. -keep class com.google.android.material.** {*;}
  107. -keep class androidx.** {*;}
  108. -keep public class * extends androidx.**
  109. -keep interface androidx.** {*;}
  110. -dontwarn com.google.android.material.**
  111. -dontnote com.google.android.material.**
  112. -dontwarn androidx.**
  113. # Compose Rules
  114. -keep class androidx.compose.** { *; }
  115. -keep class androidx.documentfile.** { *; }
  116. -keepclassmembers class androidx.documentfile.** { *; }
  117. # ...
  118. # Lifecycle
  119. -keep class * extends androidx.lifecycle.ViewModel { *; }
  120. -keep class * extends androidx.lifecycle.LifecycleObserver { *; }
  121. # Paging
  122. -keep class androidx.paging.** { *; }
  123. # Navigation
  124. -keep class androidx.navigation.** { *; }
  125. # accompanist
  126. -keep class com.google.accompanist.** { *; }
  127. # Dagger Hilt
  128. -keep class * extends com.google.dagger.hilt.android.lifecycle.*
  129. -keepclassmembers class * {
  130. javax.inject.* *;
  131. }
  132. # Multidex
  133. -keep class * extends android.app.Application {
  134. void attachBaseContext(...);
  135. }
  136. #kotlin
  137. -keep class kotlin.** { *; }
  138. -keep class kotlin.Metadata { *; }
  139. -dontwarn kotlin.**
  140. -keepclassmembers class **$WhenMappings {
  141. <fields>;
  142. }
  143. -keepclassmembers class kotlin.Metadata {
  144. public <methods>;
  145. }
  146. -assumenosideeffects class kotlin.jvm.internal.Intrinsics {
  147. static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
  148. }
  149. -keepclasseswithmembernames class * {
  150. native <methods>;
  151. }
  152. -keepclassmembers class * extends android.app.Activity {
  153. public void *(android.view.View);
  154. }
  155. -keepclassmembers class * implements android.os.Parcelable {
  156. public static final android.os.Parcelable$Creator *;
  157. }
  158. -keep class **.R$* {*;}
  159. -keepclassmembers enum * { *;}
  160. #Kotlin Coroutines
  161. -keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
  162. -keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
  163. -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
  164. -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
  165. -keepclassmembernames class kotlinx.** {
  166. volatile <fields>;
  167. }
  168. #BRVAH
  169. -keep class com.chad.library.adapter.** {
  170. *;
  171. }
  172. -keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
  173. -keep public class * extends com.chad.library.adapter.base.viewholder.BaseViewHolder
  174. -keepclassmembers class **$** extends com.chad.library.adapter.base.viewholder.BaseViewHolder {
  175. <init>(...);
  176. }
  177. # Retrofit
  178. -dontwarn retrofit2.**
  179. -keep class retrofit2.** { *; }
  180. -keepattributes Signature
  181. -keepattributes Exceptions
  182. # converters and adapters. 是否要注释
  183. -keepclassmembernames,allowobfuscation interface * {
  184. @retrofit2.http.* <methods>;
  185. }
  186. -dontwarn javax.annotation.**
  187. -dontwarn javax.inject.**
  188. #okhttp
  189. -dontwarn okhttp3.**
  190. -keep class okhttp3.**{*;}
  191. -dontwarn okhttp3.logging.**
  192. -keep class okhttp3.internal.**{*;}
  193. #okio
  194. -dontwarn okio.**
  195. -keep class okio.**{*;}
  196. # Gson
  197. -keepattributes *Annotation*
  198. -keepattributes Signature
  199. -dontwarn sun.misc.**
  200. -keep class com.google.gson.stream.** { *; }
  201. -keep class com.google.gson.examples.android.model.** { *; }
  202. -keep class * implements com.google.gson.TypeAdapterFactory
  203. -keep class * implements com.google.gson.JsonSerializer
  204. -keep class * implements com.google.gson.JsonDeserializer
  205. #XPopup
  206. -dontwarn com.lxj.xpopup.widget.**
  207. -keep class com.lxj.xpopup.widget.**{*;}
  208. -keep class com.lxj.xpopupext.bean.** {*;}
  209. #XXPermission混淆
  210. -keep class com.hjq.permissions.** {*;}
  211. -keep class com.hjq.toast.** {*;}
  212. ##腾讯
  213. -keep class com.tencent.** { *; }