proguard-rules.pro 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # 默认的混淆文件 C:\0Develop\AndroidSDK\tools\proguard\proguard-android-optimize.txt
  20. # 不应移除代码:
  21. # 当应用通过 Java 原生接口 (JNI) 调用方法时
  22. # 当您的应用在运行时查询代码时(如使用反射)
  23. # 动态生成的字符串查询资源名称时(如R.drawable.img_%1d)
  24. #不警告
  25. -dontwarn
  26. #保持自定义控件类不被混淆
  27. -keepclasseswithmembers class * {
  28. public <init>(android.content.Context, android.util.AttributeSet);
  29. }
  30. -keepclasseswithmembers class * {
  31. public <init>(android.content.Context, android.util.AttributeSet, int);
  32. }
  33. #保持 Serializable 不被混淆
  34. -keepnames class * implements java.io.Serializable
  35. -keepclassmembers class * implements java.io.Serializable {
  36. static final long serialVersionUID;
  37. private static final java.io.ObjectStreamField[] serialPersistentFields;
  38. !static !transient <fields>;
  39. !private <fields>;
  40. !private <methods>;
  41. private void writeObject(java.io.ObjectOutputStream);
  42. private void readObject(java.io.ObjectInputStream);
  43. java.lang.Object writeReplace();
  44. java.lang.Object readResolve();
  45. }
  46. #移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用,另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制
  47. -assumenosideeffects class android.util.Log {
  48. public static *** v(...);
  49. public static *** i(...);
  50. public static *** d(...);
  51. public static *** w(...);
  52. public static *** e(...);
  53. }
  54. # WebView使用javascript功能则需要开启
  55. -keepclassmembers class fqcn.of.javascript.interface.for.webview {
  56. public *;
  57. }
  58. #######################项目独有文件#################################
  59. # 如果使用了Gson之类的工具要使被它解析的JavaBean类即实体类不被混淆。
  60. -keep class com.hqumath.map.bean.**{*;}
  61. #SDK需要引用导入工程的资源文件,通过了反射机制得到资源引用文件R.java,但是在开发者通过proguard等混淆/优化工具处理apk时,proguard可能会将R.java删除,如果遇到这个问题,请添加如下配置: TODO
  62. -keep public class com.hqumath.map.R$*{
  63. public static final int *;
  64. }
  65. #######################第三方模块###################################
  66. # opengl
  67. -keep public class android.opengl.** {*;}
  68. # glide
  69. -keep public class * implements com.bumptech.glide.module.GlideModule
  70. -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  71. **[] $VALUES;
  72. public *;
  73. }
  74. # OkHttp3
  75. -keep class okhttp3.internal.**{*;}
  76. # Retrofit
  77. -keep class retrofit2.** { *; }
  78. # RxJava RxAndroid的混淆,勿动
  79. -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
  80. long producerIndex;
  81. long consumerIndex;
  82. }
  83. -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
  84. rx.internal.util.atomic.LinkedQueueNode producerNode;
  85. }
  86. -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
  87. rx.internal.util.atomic.LinkedQueueNode consumerNode;
  88. }
  89. # FastJson
  90. -keep class com.alibaba.fastjson.** { *; }
  91. # 权限 yanzhenjie.permission
  92. -keepclassmembers class ** {
  93. @com.yanzhenjie.permission.PermissionYes <methods>;
  94. }
  95. -keepclassmembers class ** {
  96. @com.yanzhenjie.permission.PermissionNo <methods>;
  97. }