cronet-proguard-rules.pro 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # -------- Config Path: base/android/proguard/chromium_code.flags --------
  2. # Copyright 2016 The Chromium Authors
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Contains flags that can be safely shared with Cronet, and thus would be
  6. # appropriate for third-party apps to include.
  7. # Allow unused native methods to be removed, but prevent renaming on those that are kept.
  8. -keepclasseswithmembernames,includedescriptorclasses,allowaccessmodification class !cr_allowunused,** {
  9. native <methods>;
  10. }
  11. # Use assumevalues block instead of assumenosideeffects block because Google3 proguard cannot parse
  12. # assumenosideeffects blocks which overwrite return value.
  13. # chromium_code.flags rather than remove_logging.flags so that it's included
  14. # in cronet.
  15. -assumevalues class org.chromium.base.Log {
  16. static boolean isDebug() return false;
  17. }
  18. # Keep all CREATOR fields within Parcelable that are kept.
  19. -keepclassmembers class !cr_allowunused,org.chromium.** implements android.os.Parcelable {
  20. public static *** CREATOR;
  21. }
  22. # Don't obfuscate Parcelables as they might be marshalled outside Chrome.
  23. # If we annotated all Parcelables that get put into Bundles other than
  24. # for saveInstanceState (e.g. PendingIntents), then we could actually keep the
  25. # names of just those ones. For now, we'll just keep them all.
  26. -keepnames,allowaccessmodification class !cr_allowunused,org.chromium.** implements android.os.Parcelable {}
  27. # Keep all enum values and valueOf methods. See
  28. # http://proguard.sourceforge.net/index.html#manual/examples.html
  29. # for the reason for this. Also, see http://crbug.com/248037.
  30. -keepclassmembers enum !cr_allowunused,org.chromium.** {
  31. public static **[] values();
  32. }
  33. # -identifiernamestring doesn't keep the module impl around, we have to
  34. # explicitly keep it.
  35. -if @org.chromium.components.module_installer.builder.ModuleInterface interface *
  36. -keep,allowobfuscation,allowaccessmodification class !cr_allowunused,** extends <1> {
  37. <init>();
  38. }
  39. # Required to remove fields until b/274802355 is resolved.
  40. -assumevalues class !cr_allowunused,** {
  41. final org.chromium.base.ThreadUtils$ThreadChecker * return _NONNULL_;
  42. }
  43. # TODO(agrieve): Remove once we start to use Android U SDK.
  44. -dontwarn android.window.BackEvent
  45. -dontwarn android.window.OnBackAnimationCallback
  46. # -------- Config Path: build/android/chromium_annotations.flags --------
  47. # Copyright 2022 The Chromium Authors
  48. # Use of this source code is governed by a BSD-style license that can be
  49. # found in the LICENSE file.
  50. # Contains flags related to annotations in //build/android that can be safely
  51. # shared with Cronet, and thus would be appropriate for third-party apps to
  52. # include.
  53. # Keep all annotation related attributes that can affect runtime
  54. -keepattributes RuntimeVisible*Annotations
  55. -keepattributes AnnotationDefault
  56. # Keeps for class level annotations.
  57. -keep,allowaccessmodification @org.chromium.build.annotations.UsedByReflection class ** {}
  58. # Keeps for method level annotations.
  59. -keepclasseswithmembers,allowaccessmodification class ** {
  60. @org.chromium.build.annotations.UsedByReflection <methods>;
  61. }
  62. -keepclasseswithmembers,allowaccessmodification class ** {
  63. @org.chromium.build.annotations.UsedByReflection <fields>;
  64. }
  65. # Never inline classes, methods, or fields with this annotation, but allow
  66. # shrinking and obfuscation.
  67. # Relevant to fields when they are needed to store strong references to objects
  68. # that are held as weak references by native code.
  69. -if @org.chromium.build.annotations.DoNotInline class * {
  70. *** *(...);
  71. }
  72. -keep,allowobfuscation,allowaccessmodification class <1> {
  73. *** <2>(...);
  74. }
  75. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  76. @org.chromium.build.annotations.DoNotInline <methods>;
  77. }
  78. -keepclassmembers,allowobfuscation,allowaccessmodification class * {
  79. @org.chromium.build.annotations.DoNotInline <fields>;
  80. }
  81. -alwaysinline class * {
  82. @org.chromium.build.annotations.AlwaysInline *;
  83. }
  84. # Keep all logs (Log.VERBOSE = 2). R8 does not allow setting to 0.
  85. -maximumremovedandroidloglevel 1 class ** {
  86. @org.chromium.build.annotations.DoNotStripLogs <methods>;
  87. }
  88. -maximumremovedandroidloglevel 1 @org.chromium.build.annotations.DoNotStripLogs class ** {
  89. <methods>;
  90. }
  91. # Never merge classes horizontally or vertically with this annotation.
  92. # Relevant to classes being used as a key in maps or sets.
  93. -keep,allowaccessmodification,allowobfuscation,allowshrinking @org.chromium.build.annotations.DoNotClassMerge class *
  94. # Mark members annotated with IdentifierNameString as identifier name strings
  95. -identifiernamestring class * {
  96. @org.chromium.build.annotations.IdentifierNameString *;
  97. }
  98. # -------- Config Path: components/cronet/android/cronet_impl_common_proguard.cfg --------
  99. # Proguard config for apps that depend on cronet_impl_common_java.jar.
  100. # Used through reflection by the API code to figure out the version of the impl
  101. # code it's talking to.
  102. -keep public class org.chromium.net.impl.ImplVersion {
  103. public *;
  104. }
  105. -dontwarn com.google.errorprone.annotations.DoNotMock
  106. # -------- Config Path: components/cronet/android/cronet_impl_native_proguard.cfg --------
  107. # Proguard config for apps that depend on cronet_impl_native_java.jar.
  108. # This constructor is called using the reflection from Cronet API (cronet_api.jar).
  109. -keep class org.chromium.net.impl.NativeCronetProvider {
  110. public <init>(android.content.Context);
  111. }
  112. # While Chrome doesn't need to keep these with their version of R8, some cronet
  113. # users may be on other optimizers which still require the annotation to be
  114. # kept in order for the keep rules to work.
  115. -keep @interface org.chromium.build.annotations.DoNotInline
  116. -keep @interface org.chromium.build.annotations.UsedByReflection
  117. -keep @interface org.chromium.build.annotations.IdentifierNameString
  118. -keep @interface org.jni_zero.AccessedByNative
  119. -keep @interface org.jni_zero.CalledByNative
  120. -keep @interface org.jni_zero.CalledByNativeUnchecked
  121. # Suppress unnecessary warnings.
  122. -dontnote org.chromium.net.ProxyChangeListener$ProxyReceiver
  123. -dontnote org.chromium.net.AndroidKeyStore
  124. # Needs 'void setTextAppearance(int)' (API level 23).
  125. -dontwarn org.chromium.base.ApiCompatibilityUtils
  126. # Needs 'boolean onSearchRequested(android.view.SearchEvent)' (API level 23).
  127. -dontwarn org.chromium.base.WindowCallbackWrapper
  128. # Generated for chrome apk and not included into cronet.
  129. -dontwarn org.chromium.base.multidex.ChromiumMultiDexInstaller
  130. -dontwarn org.chromium.base.library_loader.LibraryLoader
  131. -dontwarn org.chromium.base.SysUtils
  132. -dontwarn org.chromium.build.NativeLibraries
  133. # Objects of this type are passed around by native code, but the class
  134. # is never used directly by native code. Since the class is not loaded, it does
  135. # not need to be preserved as an entry point.
  136. -dontnote org.chromium.net.UrlRequest$ResponseHeadersMap
  137. # https://android.googlesource.com/platform/sdk/+/marshmallow-mr1-release/files/proguard-android.txt#54
  138. -dontwarn android.support.**
  139. # This class should be explicitly kept to avoid failure if
  140. # class/merging/horizontal proguard optimization is enabled.
  141. -keep class org.chromium.base.CollectionUtil
  142. # Skip protobuf runtime check for isOnAndroidDevice().
  143. # A nice-to-have optimization shamelessly stolen from //third_party/protobuf/java/lite/proguard.pgcfg.
  144. -assumevalues class com.google.protobuf.Android {
  145. static boolean ASSUME_ANDROID return true;
  146. }
  147. # See crbug.com/1440987. We must keep every native that we are manually
  148. # registering. If Cronet bumps its min-sdk past 21, we may be able to move to
  149. # automatic JNI registration.
  150. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class org.chromium.**,J.N {
  151. native <methods>;
  152. }
  153. # Protobuf builder uses reflection so make sure ProGuard leaves it alone. See
  154. # https://crbug.com/1395764.
  155. # Note that we can't simply use the rule from
  156. # //third_party/protobuf/java/lite/proguard.pgcfg, because some users who
  157. # consume our ProGuard rules do not want all their protos to be kept. Instead,
  158. # use a more specific rule that covers Chromium protos only.
  159. -keepclassmembers class org.chromium.** extends com.google.protobuf.GeneratedMessageLite {
  160. <fields>;
  161. }
  162. # -------- Config Path: components/cronet/android/cronet_shared_proguard.cfg --------
  163. # Proguard config for apps that depend on cronet_shared_java.jar (which should
  164. # be all apps that depend on any part of Cronet)
  165. # Part of the Android System SDK, so ProGuard won't be able to resolve it if
  166. # running against the standard SDK.
  167. -dontwarn android.util.StatsEvent
  168. -dontwarn android.util.StatsEvent$*
  169. # There is also an undefined reference to android.util.StatsLog.write(), which
  170. # R8 appears to be fine with but other processors (e.g. internal Google
  171. # ProGuard) may not be. See b/315269496.
  172. -dontwarn android.util.StatsLog
  173. # -------- Config Path: third_party/androidx/androidx_annotations.flags --------
  174. # Copyright 2023 The Chromium Authors
  175. # Use of this source code is governed by a BSD-style license that can be
  176. # found in the LICENSE file.
  177. -keep @androidx.annotation.Keep class *
  178. -keepclasseswithmembers,allowaccessmodification class * {
  179. @androidx.annotation.Keep <fields>;
  180. }
  181. -keepclasseswithmembers,allowaccessmodification class * {
  182. @androidx.annotation.Keep <methods>;
  183. }
  184. # -------- Config Path: third_party/jni_zero/proguard.flags --------
  185. # Copyright 2023 The Chromium Authors
  186. # Use of this source code is governed by a BSD-style license that can be
  187. # found in the LICENSE file.
  188. # Keeps for method level annotations.
  189. -keepclasseswithmembers,allowaccessmodification class ** {
  190. @org.jni_zero.AccessedByNative <fields>;
  191. }
  192. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  193. @org.jni_zero.CalledByNative <methods>;
  194. }
  195. -keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** {
  196. @org.jni_zero.CalledByNativeUnchecked <methods>;
  197. }