proguard-rules.pro 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. -dontwarn org.commonmark.ext.gfm.**
  148. -keep class com.google.gson.** { *; }
  149. -keep class com.ke.gson.** { *; }
  150. -keep class com.jeremyliao.liveeventbus.** { *; }
  151. -keep class okhttp3.**{*;}
  152. -keep class okio.**{*;}
  153. -keep class com.hwangjr.rxbus.**{*;}
  154. -keep class org.conscrypt.**{*;}
  155. -keep class android.support.**{*;}
  156. -keep class me.grantland.widget.**{*;}
  157. -keep class de.hdodenhof.circleimageview.**{*;}
  158. -keep class tyrant.explosionfield.**{*;}
  159. -keep class tyrantgit.explosionfield.**{*;}
  160. -keep class freemarker.**{*;}
  161. -keep class com.gyf.barlibrary.** {*;}
  162. ##JSOUP
  163. -keep class org.jsoup.**{*;}
  164. -keep class **.xpath.**{*;}
  165. -keep class org.slf4j.**{*;}
  166. -dontwarn org.slf4j.**
  167. -keep class org.codehaus.**{*;}
  168. -dontwarn org.codehaus.**
  169. -keep class com.jayway.**{*;}
  170. -dontwarn com.jayway.**
  171. -keep class com.fasterxml.**{*;}
  172. -keep class javax.swing.**{*;}
  173. -dontwarn javax.swing.**
  174. -keep class java.awt.**{*;}
  175. -dontwarn java.awt.**
  176. -keep class sun.misc.**{*;}
  177. -dontwarn sun.misc.**
  178. -keep class sun.reflect.**{*;}
  179. -dontwarn sun.reflect.**
  180. ## Rhino
  181. -keep class javax.script.** { *; }
  182. -keep class com.sun.script.javascript.** { *; }
  183. -keep class org.mozilla.javascript.** { *; }
  184. ###EPUB
  185. -dontwarn nl.siegmann.epublib.**
  186. -dontwarn org.xmlpull.**
  187. -keep class nl.siegmann.epublib.**{*;}
  188. -keep class javax.xml.**{*;}
  189. -keep class org.xmlpull.**{*;}
  190. -keep class org.simpleframework.**{*;}
  191. -dontwarn org.simpleframework.xml.**
  192. -keepclassmembers class * {
  193. public <init> (org.json.JSONObject);
  194. }
  195. -keepclassmembers enum * {
  196. public static **[] values();
  197. public static ** valueOf(java.lang.String);
  198. }
  199. ## ExoPlayer 反射设置ua 保证该私有变量不被混淆
  200. -keepclassmembers class com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory {
  201. *** upstreamDataSourceFactory;
  202. }
  203. ## ExoPlayer 如果还不能播放就取消注释这个
  204. # -keep class com.google.android.exoplayer2.** {*;}
  205. ## 对外提供api
  206. -keep class io.legado.app.api.ReturnData{*;}
  207. #-------------------Cronet------------------------------------
  208. # Contains flags that can be safely shared with Cronet, and thus would be
  209. # appropriate for third-party apps to include.
  210. # Keep all annotation related attributes that can affect runtime
  211. -keepattributes RuntimeVisible*Annotations
  212. -keepattributes AnnotationDefault
  213. # Keep the annotations, because if we don't, the ProGuard rules that use them
  214. # will not be respected. These classes then show up in our final dex, which we
  215. # do not want - see crbug.com/628226.
  216. -keep @interface org.chromium.base.annotations.AccessedByNative
  217. -keep @interface org.chromium.base.annotations.CalledByNative
  218. -keep @interface org.chromium.base.annotations.CalledByNativeUnchecked
  219. -keep @interface org.chromium.base.annotations.DoNotInline
  220. -keep @interface org.chromium.base.annotations.UsedByReflection
  221. -keep @interface org.chromium.base.annotations.IdentifierNameString
  222. # Android support library annotations will get converted to androidx ones
  223. # which we want to keep.
  224. -keep @interface androidx.annotation.Keep
  225. -keep @androidx.annotation.Keep class *
  226. -keepclasseswithmembers,allowaccessmodification class * {
  227. @androidx.annotation.Keep <fields>;
  228. }
  229. -keepclasseswithmembers,allowaccessmodification class * {
  230. @androidx.annotation.Keep <methods>;
  231. }
  232. # Keeps for class level annotations.
  233. -keep,allowaccessmodification @org.chromium.base.annotations.UsedByReflection class ** {}
  234. # Keeps for method level annotations.
  235. -keepclasseswithmembers,allowaccessmodification class ** {
  236. @org.chromium.base.annotations.AccessedByNative <fields>;
  237. }
  238. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  239. @org.chromium.base.annotations.CalledByNative <methods>;
  240. }
  241. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  242. @org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
  243. }
  244. -keepclasseswithmembers,allowaccessmodification class ** {
  245. @org.chromium.base.annotations.UsedByReflection <methods>;
  246. }
  247. -keepclasseswithmembers,allowaccessmodification class ** {
  248. @org.chromium.base.annotations.UsedByReflection <fields>;
  249. }
  250. # Even unused methods kept due to explicit jni registration:
  251. # https://crbug.com/688465.
  252. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class !org.chromium.base.library_loader.**,** {
  253. native <methods>;
  254. }
  255. -keepclasseswithmembernames,includedescriptorclasses,allowaccessmodification class org.chromium.base.library_loader.** {
  256. native <methods>;
  257. }
  258. # Use assumevalues block instead of assumenosideeffects block because Google3 proguard cannot parse
  259. # assumenosideeffects blocks which overwrite return value.
  260. -assumevalues class org.chromium.base.Log {
  261. static boolean isDebug() return false;
  262. }
  263. # Never inline classes, methods, or fields with this annotation, but allow
  264. # shrinking and obfuscation.
  265. # Relevant to fields when they are needed to store strong references to objects
  266. # that are held as weak references by native code.
  267. -if @org.chromium.base.annotations.DoNotInline class * {
  268. *** *(...);
  269. }
  270. -keep,allowobfuscation,allowaccessmodification class <1> {
  271. *** <2>(...);
  272. }
  273. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  274. @org.chromium.base.annotations.DoNotInline <methods>;
  275. }
  276. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  277. @org.chromium.base.annotations.DoNotInline <fields>;
  278. }
  279. # Never merge classes horizontally or vertically with this annotation.
  280. # Relevant to classes being used as a key in maps or sets.
  281. -keep,allowaccessmodification,allowobfuscation,allowshrinking @org.chromium.base.annotations.DoNotClassMerge class *
  282. # Keep all CREATOR fields within Parcelable that are kept.
  283. -keepclassmembers class org.chromium.** implements android.os.Parcelable {
  284. public static *** CREATOR;
  285. }
  286. # Don't obfuscate Parcelables as they might be marshalled outside Chrome.
  287. # If we annotated all Parcelables that get put into Bundles other than
  288. # for saveInstanceState (e.g. PendingIntents), then we could actually keep the
  289. # names of just those ones. For now, we'll just keep them all.
  290. -keepnames,allowaccessmodification class org.chromium.** implements android.os.Parcelable {}
  291. # Keep all enum values and valueOf methods. See
  292. # http://proguard.sourceforge.net/index.html#manual/examples.html
  293. # for the reason for this. Also, see http://crbug.com/248037.
  294. -keepclassmembers enum org.chromium.** {
  295. public static **[] values();
  296. }
  297. # Mark members annotated with IdentifierNameString as identifier name strings
  298. -identifiernamestring class * {
  299. @org.chromium.base.annotations.IdentifierNameString *;
  300. }
  301. # -identifiernamestring doesn't keep the module impl around, we have to
  302. # explicitly keep it.
  303. -if @org.chromium.components.module_installer.builder.ModuleInterface interface *
  304. -keep,allowobfuscation,allowaccessmodification class * extends <1> {
  305. <init>();
  306. }
  307. # Proguard config for apps that depend on cronet_impl_native_java.jar.
  308. # This constructor is called using the reflection from Cronet API (cronet_api.jar).
  309. -keep class * extends org.chromium.net.CronetProvider{
  310. public <init>(android.content.Context);
  311. }
  312. # Suppress unnecessary warnings.
  313. -dontnote org.chromium.net.ProxyChangeListener$ProxyReceiver
  314. -dontnote org.chromium.net.AndroidKeyStore
  315. # Needs 'void setTextAppearance(int)' (API level 23).
  316. -dontwarn org.chromium.base.ApiCompatibilityUtils
  317. # Needs 'boolean onSearchRequested(android.view.SearchEvent)' (API level 23).
  318. -dontwarn org.chromium.base.WindowCallbackWrapper
  319. # Generated for chrome apk and not included into cronet.
  320. -dontwarn org.chromium.base.multidex.ChromiumMultiDexInstaller
  321. -dontwarn org.chromium.base.library_loader.LibraryLoader
  322. -dontwarn org.chromium.base.SysUtils
  323. -dontwarn org.chromium.build.NativeLibraries
  324. # Objects of this type are passed around by native code, but the class
  325. # is never used directly by native code. Since the class is not loaded, it does
  326. # not need to be preserved as an entry point.
  327. -dontnote org.chromium.net.UrlRequest$ResponseHeadersMap
  328. # https://android.googlesource.com/platform/sdk/+/marshmallow-mr1-release/files/proguard-android.txt#54
  329. -dontwarn android.support.**
  330. # This class should be explicitly kept to avoid failure if
  331. # class/merging/horizontal proguard optimization is enabled.
  332. -keep class org.chromium.base.CollectionUtil
  333. #-------------------Cronet------------------------------------
  334. # Class.forName调用
  335. -keep class io.legado.app.lib.cronet.CronetInterceptor{*;}
  336. -keep class io.legado.app.lib.cronet.CronetLoader{*;}
  337. -keep class io.legado.app.help.AppUpdateGitHub{*;}