proguard-rules.pro 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. # Add project specific ProGuard rules here.
  2. # You can control the set of applied configuration files using the
  3. # proguardFiles setting in build.gradle.
  4. #
  5. # For more details, see
  6. # http://developer.android.com/guide/developing/tools/proguard.html
  7. # If your project uses WebView with JS, uncomment the following
  8. # and specify the fully qualified class name to the JavaScript interface
  9. # class:
  10. #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  11. # public *;
  12. #}
  13. # Uncomment this to preserve the line number information for
  14. # debugging stack traces.
  15. #-keepattributes SourceFile,LineNumberTable
  16. # If you keep the line number information, uncomment this to
  17. # hide the original source file name.
  18. #-renamesourcefileattribute SourceFile
  19. # 混合时不使用大小写混合,混合后的类名为小写
  20. -dontusemixedcaseclassnames
  21. # 指定不去忽略非公共库的类
  22. -dontskipnonpubliclibraryclasses
  23. # 这句话能够使我们的项目混淆后产生映射文件
  24. # 包含有类名->混淆后类名的映射关系
  25. -verbose
  26. # 指定不去忽略非公共库的类成员
  27. -dontskipnonpubliclibraryclassmembers
  28. # 不做预校验,preverify是proguard的四个步骤之一,Android不需要preverify,去掉这一步能够加快混淆速度。
  29. -dontpreverify
  30. # 保留Annotation不混淆
  31. -keepattributes *Annotation*,InnerClasses
  32. # 避免混淆泛型
  33. -keepattributes Signature
  34. # 抛出异常时保留代码行号
  35. -keepattributes SourceFile,LineNumberTable
  36. # 指定混淆是采用的算法,后面的参数是一个过滤器
  37. # 这个过滤器是谷歌推荐的算法,一般不做更改
  38. -optimizations !code/simplification/cast,!field/*,!class/merging/*
  39. #############################################
  40. #
  41. # Android开发中一些需要保留的公共部分
  42. #
  43. #############################################
  44. # 屏蔽错误Unresolved class name
  45. #noinspection ShrinkerUnresolvedReference
  46. # 保留我们使用的四大组件,自定义的Application等等这些类不被混淆
  47. # 因为这些子类都有可能被外部调用
  48. -keep public class * extends android.app.Activity
  49. -keep public class * extends android.app.Application
  50. -keep public class * extends android.app.Service
  51. -keep public class * extends android.content.BroadcastReceiver
  52. -keep public class * extends android.content.ContentProvider
  53. -keep public class * extends android.app.backup.BackupAgentHelper
  54. -keep public class * extends android.preference.Preference
  55. -keep public class * extends android.view.View
  56. # 保留androidx下的所有类及其内部类
  57. -keep class androidx.** {*;}
  58. # 保留继承的
  59. -keep public class * extends androidx.**
  60. # 保留R下面的资源
  61. -keep class **.R$* {*;}
  62. # 保留本地native方法不被混淆
  63. -keepclasseswithmembernames class * {
  64. native <methods>;
  65. }
  66. # 保留在Activity中的方法参数是view的方法,
  67. # 这样以来我们在layout中写的onClick就不会被影响
  68. -keepclassmembers class * extends android.app.Activity{
  69. public void *(android.view.View);
  70. }
  71. # 保留枚举类不被混淆
  72. -keepclassmembers enum * {
  73. public static **[] values();
  74. public static ** valueOf(java.lang.String);
  75. }
  76. # 保留我们自定义控件(继承自View)不被混淆
  77. -keep public class * extends android.view.View{
  78. *** get*();
  79. void set*(***);
  80. public <init>(android.content.Context);
  81. public <init>(android.content.Context, android.util.AttributeSet);
  82. public <init>(android.content.Context, android.util.AttributeSet, int);
  83. }
  84. # 保留Parcelable序列化类不被混淆
  85. -keep class * implements android.os.Parcelable {
  86. public static final android.os.Parcelable$Creator *;
  87. }
  88. # 保留Serializable序列化的类不被混淆
  89. -keepclassmembers class * implements java.io.Serializable {
  90. static final long serialVersionUID;
  91. private static final java.io.ObjectStreamField[] serialPersistentFields;
  92. !static !transient <fields>;
  93. !private <fields>;
  94. !private <methods>;
  95. private void writeObject(java.io.ObjectOutputStream);
  96. private void readObject(java.io.ObjectInputStream);
  97. java.lang.Object writeReplace();
  98. java.lang.Object readResolve();
  99. }
  100. # 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
  101. -keepclassmembers class * {
  102. void *(**On*Event);
  103. void *(**On*Listener);
  104. }
  105. # webView处理,项目中没有使用到webView忽略即可
  106. -keepclassmembers class * extends android.webkit.WebViewClient {
  107. public void *(android.webkit.WebView, java.lang.String);
  108. public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
  109. public boolean *(android.webkit.WebView, java.lang.String);
  110. }
  111. # 移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用
  112. # 记得proguard-android.txt中一定不要加-dontoptimize才起作用
  113. # 另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制
  114. -assumenosideeffects class android.util.Log {
  115. public static int v(...);
  116. public static int i(...);
  117. public static int w(...);
  118. public static int d(...);
  119. public static int e(...);
  120. }
  121. # 保持js引擎调用的java类
  122. -keep class **.analyzeRule.**{*;}
  123. # 保持web类
  124. -keep class **.web.**{*;}
  125. # 数据类
  126. -keep class **.data.**{*;}
  127. # hutool-core hutool-crypto
  128. -keep class cn.hutool.core.**{*;}
  129. -keep class cn.hutool.crypto.**{*;}
  130. -dontwarn cn.hutool.**
  131. # 缓存 Cookie
  132. -keep class **.help.http.CookieStore{*;}
  133. -keep class **.help.CacheManager{*;}
  134. # StrResponse
  135. -keep class **.help.http.StrResponse{*;}
  136. -dontwarn rx.**
  137. -dontwarn okio.**
  138. -dontwarn javax.annotation.**
  139. -dontwarn org.apache.log4j.lf5.viewer.**
  140. -dontnote org.apache.log4j.lf5.viewer.**
  141. -dontwarn freemarker.**
  142. -dontnote org.python.core.**
  143. -dontwarn com.hwangjr.rxbus.**
  144. -dontwarn okhttp3.**
  145. -dontwarn org.conscrypt.**
  146. -dontwarn com.jeremyliao.liveeventbus.**
  147. -keep class com.google.gson.** { *; }
  148. -keep class com.ke.gson.** { *; }
  149. -keep class com.jeremyliao.liveeventbus.** { *; }
  150. -keep class okhttp3.**{*;}
  151. -keep class okio.**{*;}
  152. -keep class com.hwangjr.rxbus.**{*;}
  153. -keep class org.conscrypt.**{*;}
  154. -keep class android.support.**{*;}
  155. -keep class me.grantland.widget.**{*;}
  156. -keep class de.hdodenhof.circleimageview.**{*;}
  157. -keep class tyrant.explosionfield.**{*;}
  158. -keep class tyrantgit.explosionfield.**{*;}
  159. -keep class freemarker.**{*;}
  160. -keep class com.gyf.barlibrary.** {*;}
  161. ##JSOUP
  162. -keep class org.jsoup.**{*;}
  163. -keep class **.xpath.**{*;}
  164. -keep class org.slf4j.**{*;}
  165. -dontwarn org.slf4j.**
  166. -keep class org.codehaus.**{*;}
  167. -dontwarn org.codehaus.**
  168. -keep class com.jayway.**{*;}
  169. -dontwarn com.jayway.**
  170. -keep class com.fasterxml.**{*;}
  171. -keep class javax.swing.**{*;}
  172. -dontwarn javax.swing.**
  173. -keep class java.awt.**{*;}
  174. -dontwarn java.awt.**
  175. -keep class sun.misc.**{*;}
  176. -dontwarn sun.misc.**
  177. -keep class sun.reflect.**{*;}
  178. -dontwarn sun.reflect.**
  179. ## Rhino
  180. -keep class javax.script.** { *; }
  181. -keep class com.sun.script.javascript.** { *; }
  182. -keep class org.mozilla.javascript.** { *; }
  183. ###EPUB
  184. -dontwarn nl.siegmann.epublib.**
  185. -dontwarn org.xmlpull.**
  186. -keep class nl.siegmann.epublib.**{*;}
  187. -keep class javax.xml.**{*;}
  188. -keep class org.xmlpull.**{*;}
  189. -keep class org.simpleframework.**{*;}
  190. -dontwarn org.simpleframework.xml.**
  191. -keepclassmembers class * {
  192. public <init> (org.json.JSONObject);
  193. }
  194. -keepclassmembers enum * {
  195. public static **[] values();
  196. public static ** valueOf(java.lang.String);
  197. }
  198. ## ExoPlayer 反射设置ua 保证该私有变量不被混淆
  199. -keepclassmembers class com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory {
  200. *** upstreamDataSourceFactory;
  201. }
  202. ## ExoPlayer 如果还不能播放就取消注释这个
  203. # -keep class com.google.android.exoplayer2.** {*;}
  204. ## 对外提供api
  205. -keep class io.legado.app.api.ReturnData{*;}
  206. #-------------------Cronet------------------------------------
  207. # Contains flags that can be safely shared with Cronet, and thus would be
  208. # appropriate for third-party apps to include.
  209. # Keep all annotation related attributes that can affect runtime
  210. -keepattributes RuntimeVisible*Annotations
  211. -keepattributes AnnotationDefault
  212. # Keep the annotations, because if we don't, the ProGuard rules that use them
  213. # will not be respected. These classes then show up in our final dex, which we
  214. # do not want - see crbug.com/628226.
  215. -keep @interface org.chromium.base.annotations.AccessedByNative
  216. -keep @interface org.chromium.base.annotations.CalledByNative
  217. -keep @interface org.chromium.base.annotations.CalledByNativeUnchecked
  218. -keep @interface org.chromium.base.annotations.DoNotInline
  219. -keep @interface org.chromium.base.annotations.UsedByReflection
  220. -keep @interface org.chromium.base.annotations.IdentifierNameString
  221. # Android support library annotations will get converted to androidx ones
  222. # which we want to keep.
  223. -keep @interface androidx.annotation.Keep
  224. -keep @androidx.annotation.Keep class *
  225. -keepclasseswithmembers,allowaccessmodification class * {
  226. @androidx.annotation.Keep <fields>;
  227. }
  228. -keepclasseswithmembers,allowaccessmodification class * {
  229. @androidx.annotation.Keep <methods>;
  230. }
  231. # Keeps for class level annotations.
  232. -keep,allowaccessmodification @org.chromium.base.annotations.UsedByReflection class ** {}
  233. # Keeps for method level annotations.
  234. -keepclasseswithmembers,allowaccessmodification class ** {
  235. @org.chromium.base.annotations.AccessedByNative <fields>;
  236. }
  237. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  238. @org.chromium.base.annotations.CalledByNative <methods>;
  239. }
  240. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  241. @org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
  242. }
  243. -keepclasseswithmembers,allowaccessmodification class ** {
  244. @org.chromium.base.annotations.UsedByReflection <methods>;
  245. }
  246. -keepclasseswithmembers,allowaccessmodification class ** {
  247. @org.chromium.base.annotations.UsedByReflection <fields>;
  248. }
  249. # Even unused methods kept due to explicit jni registration:
  250. # https://crbug.com/688465.
  251. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class !org.chromium.base.library_loader.**,** {
  252. native <methods>;
  253. }
  254. -keepclasseswithmembernames,includedescriptorclasses,allowaccessmodification class org.chromium.base.library_loader.** {
  255. native <methods>;
  256. }
  257. # Use assumevalues block instead of assumenosideeffects block because Google3 proguard cannot parse
  258. # assumenosideeffects blocks which overwrite return value.
  259. -assumevalues class org.chromium.base.Log {
  260. static boolean isDebug() return false;
  261. }
  262. # Never inline classes, methods, or fields with this annotation, but allow
  263. # shrinking and obfuscation.
  264. # Relevant to fields when they are needed to store strong references to objects
  265. # that are held as weak references by native code.
  266. -if @org.chromium.base.annotations.DoNotInline class * {
  267. *** *(...);
  268. }
  269. -keep,allowobfuscation,allowaccessmodification class <1> {
  270. *** <2>(...);
  271. }
  272. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  273. @org.chromium.base.annotations.DoNotInline <methods>;
  274. }
  275. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  276. @org.chromium.base.annotations.DoNotInline <fields>;
  277. }
  278. # Never merge classes horizontally or vertically with this annotation.
  279. # Relevant to classes being used as a key in maps or sets.
  280. -keep,allowaccessmodification,allowobfuscation,allowshrinking @org.chromium.base.annotations.DoNotClassMerge class *
  281. # Keep all CREATOR fields within Parcelable that are kept.
  282. -keepclassmembers class org.chromium.** implements android.os.Parcelable {
  283. public static *** CREATOR;
  284. }
  285. # Don't obfuscate Parcelables as they might be marshalled outside Chrome.
  286. # If we annotated all Parcelables that get put into Bundles other than
  287. # for saveInstanceState (e.g. PendingIntents), then we could actually keep the
  288. # names of just those ones. For now, we'll just keep them all.
  289. -keepnames,allowaccessmodification class org.chromium.** implements android.os.Parcelable {}
  290. # Keep all enum values and valueOf methods. See
  291. # http://proguard.sourceforge.net/index.html#manual/examples.html
  292. # for the reason for this. Also, see http://crbug.com/248037.
  293. -keepclassmembers enum org.chromium.** {
  294. public static **[] values();
  295. }
  296. # Mark members annotated with IdentifierNameString as identifier name strings
  297. -identifiernamestring class * {
  298. @org.chromium.base.annotations.IdentifierNameString *;
  299. }
  300. # -identifiernamestring doesn't keep the module impl around, we have to
  301. # explicitly keep it.
  302. -if @org.chromium.components.module_installer.builder.ModuleInterface interface *
  303. -keep,allowobfuscation,allowaccessmodification class * extends <1> {
  304. <init>();
  305. }
  306. # Proguard config for apps that depend on cronet_impl_native_java.jar.
  307. # This constructor is called using the reflection from Cronet API (cronet_api.jar).
  308. -keep class * extends org.chromium.net.CronetProvider{
  309. public <init>(android.content.Context);
  310. }
  311. # Suppress unnecessary warnings.
  312. -dontnote org.chromium.net.ProxyChangeListener$ProxyReceiver
  313. -dontnote org.chromium.net.AndroidKeyStore
  314. # Needs 'void setTextAppearance(int)' (API level 23).
  315. -dontwarn org.chromium.base.ApiCompatibilityUtils
  316. # Needs 'boolean onSearchRequested(android.view.SearchEvent)' (API level 23).
  317. -dontwarn org.chromium.base.WindowCallbackWrapper
  318. # Generated for chrome apk and not included into cronet.
  319. -dontwarn org.chromium.base.multidex.ChromiumMultiDexInstaller
  320. -dontwarn org.chromium.base.library_loader.LibraryLoader
  321. -dontwarn org.chromium.base.SysUtils
  322. -dontwarn org.chromium.build.NativeLibraries
  323. # Objects of this type are passed around by native code, but the class
  324. # is never used directly by native code. Since the class is not loaded, it does
  325. # not need to be preserved as an entry point.
  326. -dontnote org.chromium.net.UrlRequest$ResponseHeadersMap
  327. # https://android.googlesource.com/platform/sdk/+/marshmallow-mr1-release/files/proguard-android.txt#54
  328. -dontwarn android.support.**
  329. # This class should be explicitly kept to avoid failure if
  330. # class/merging/horizontal proguard optimization is enabled.
  331. -keep class org.chromium.base.CollectionUtil
  332. #-------------------Cronet------------------------------------