cronet-proguard-rules.pro 9.8 KB

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