proguard-rules.pro 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. -optimizationpasses 5
  21. #不跳过非公共的库的类成员
  22. -dontskipnonpubliclibraryclassmembers
  23. #混淆时采用的算法
  24. -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
  25. #把混淆类中的方法名也混淆了
  26. -useuniqueclassmembernames
  27. #指定不去忽略非公共的库的类
  28. -dontskipnonpubliclibraryclasses
  29. #不做预检验,preverify是proguard的四大步骤之一,可以加快混淆速度
  30. #-dontpreverify
  31. # 忽略警告(?)
  32. #-ignorewarnings
  33. #混淆时不使用大小写混合,混淆后的类名为小写(大小写混淆容易导致class文件相互覆盖)
  34. -dontusemixedcaseclassnames
  35. #优化时允许访问并修改有修饰符的类和类的成员
  36. -allowaccessmodification
  37. #将文件来源重命名为“SourceFile”字符串
  38. #-renamesourcefileattribute SourceFile
  39. #保留行号
  40. -keepattributes SourceFile,LineNumberTable
  41. #保持泛型
  42. -keepattributes Signature
  43. # 保持注解
  44. -keepattributes *Annotation*,InnerClasses
  45. # Parcelable
  46. -keep class * implements android.os.Parcelable {
  47. public static final android.os.Parcelable$Creator *;
  48. }
  49. # Serializable
  50. -keepnames class * implements java.io.Serializable
  51. -keepclassmembers class * implements java.io.Serializable {
  52. private static final java.io.ObjectStreamField[] serialPersistentFields;
  53. private void writeObject(java.io.ObjectOutputStream);
  54. private void readObject(java.io.ObjectInputStream);
  55. java.lang.Object writeReplace();
  56. java.lang.Object readResolve();
  57. }
  58. ##---------------Begin: proguard configuration for Gson ----------
  59. # Gson uses generic type information stored in a class file when working with fields. Proguard
  60. # removes such information by default, so configure it to keep all of it.
  61. -keepattributes Signature
  62. # For using GSON @Expose annotation
  63. -keepattributes *Annotation*
  64. # Gson specific classes
  65. -dontwarn sun.misc.**
  66. #-keep class com.google.gson.stream.** { *; }
  67. # Application classes that will be serialized/deserialized over Gson
  68. -keep class com.google.gson.examples.android.model.** { <fields>; }
  69. # Prevent proguard from stripping interface information from TypeAdapterFactory,
  70. # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
  71. -keep class * implements com.google.gson.TypeAdapterFactory
  72. -keep class * implements com.google.gson.JsonSerializer
  73. -keep class * implements com.google.gson.JsonDeserializer
  74. # Prevent R8 from leaving Data object members always null
  75. -keepclassmembers,allowobfuscation class * {
  76. @com.google.gson.annotations.SerializedName <fields>;
  77. }
  78. ##---------------End: proguard configuration for Gson ----------
  79. # 保留R下面的资源
  80. -keep class **.R$* {*;}
  81. # 保留四大组件,自定义的Application,Fragment等这些类不被混淆
  82. -keep public class * extends android.app.Activity
  83. -keep public class * extends android.app.Fragment
  84. -keep public class * extends android.app.Application
  85. -keep public class * extends android.app.Service
  86. -keep public class * extends android.content.BroadcastReceiver
  87. -keep public class * extends android.content.ContentProvider
  88. -keep public class * extends android.app.backup.BackupAgentHelper
  89. -keep public class * extends android.preference.Preference
  90. ## support
  91. -dontwarn android.support.**
  92. -keep class android.support.v4.app.** { *; }
  93. -keep interface android.support.v4.app.** { *;}
  94. -keep public class * extends android.support.v7.**
  95. -keep public class * extends android.support.annotation.**
  96. -keep public class * extends android.support.v4.view.ActionProvider {
  97. public <init>(android.content.Context);
  98. }
  99. # 保留枚举类不被混淆
  100. -keepclassmembers enum * {
  101. public static **[] values();
  102. public static ** valueOf(java.lang.String);
  103. }
  104. # 保留本地native方法不被混淆
  105. -keepclasseswithmembers class * {
  106. native <methods>;
  107. }
  108. # 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
  109. -keepclassmembers class * {
  110. void *(**On*Event);
  111. void *(**On*Listener);
  112. }
  113. -keepclassmembers public class * extends android.view.View {
  114. void set*(***);
  115. *** get*();
  116. }
  117. #保留在Activity中的方法参数是view的方法,
  118. -keepclassmembers class * extends android.app.Activity {
  119. public void *(android.view.View);
  120. }
  121. # For XML inflating, keep views' constructoricon.png 自定义view
  122. -keep public class * extends android.view.View {
  123. public <init>(android.content.Context);
  124. public <init>(android.content.Context, android.util.AttributeSet);
  125. public <init>(android.content.Context, android.util.AttributeSet, int);
  126. public void set*(...);
  127. }
  128. # androidx 混淆
  129. -keep class com.google.android.material.** {*;}
  130. -keep class androidx.** {*;}
  131. -keep public class * extends androidx.**
  132. -keep interface androidx.** {*;}
  133. -dontwarn com.google.android.material.**
  134. -dontnote com.google.android.material.**
  135. -dontwarn androidx.**
  136. -printconfiguration
  137. -keep,allowobfuscation @interface androidx.annotation.Keep
  138. -keep @androidx.annotation.Keep class *
  139. -keepclassmembers class * {
  140. @androidx.annotation.Keep *;
  141. }
  142. # 内部WebView混淆过滤
  143. -keepclassmembers class * {
  144. @android.webkit.JavascriptInterface <methods>;
  145. }
  146. -keep class com.naz.sdkdemo.bean.**{*;}
  147. -keepclassmembers class *{
  148. public<init>(org.json.JSONObject);
  149. }
  150. -keepclassmembers enum *{
  151. publicstatic**[] values();
  152. publicstatic** valueOf(java.lang.String);
  153. }
  154. #okhttp
  155. -dontwarn okhttp3.**
  156. -keep class okhttp3.**{*;}
  157. #okio
  158. -dontwarn okio.**
  159. -keep class okio.**{*;}