| # Keep classes and members with the platform-defined @VisibleForTesting annotation. | |
| -keep @com.android.internal.annotations.VisibleForTesting class * | |
| -keepclassmembers class * { | |
| @com.android.internal.annotations.VisibleForTesting *; | |
| } | |
| # Keep classes and members with platform @TestApi annotations, similar to | |
| # @VisibleForTesting. | |
| -keep @android.annotation.TestApi class * | |
| -keepclassmembers class * { | |
| @android.annotation.TestApi *; | |
| } | |
| # Keep classes and members with non-platform @VisibleForTesting annotations, but | |
| # only within platform-defined packages. This avoids keeping external, library-specific | |
| # test code that isn't actually needed for platform testing. | |
| # TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting | |
| # and com.google.common.annotations.VisibleForTesting use in platform code. | |
| -keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.** | |
| -keepclassmembers class android.**,com.android.**,com.google.android.** { | |
| @**.VisibleForTesting *; | |
| } | |
| # Keep rule for members that are needed solely to keep alive downstream weak | |
| # references, and could otherwise be removed after tree shaking optimizations. | |
| -keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * { | |
| @com.android.internal.annotations.KeepForWeakReference <fields>; | |
| } | |
| # Needed to ensure callback field references are kept in their respective | |
| # owning classes when the downstream callback registrars only store weak refs. | |
| -if @com.android.internal.annotations.WeaklyReferencedCallback class * | |
| -keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * { | |
| !synthetic <1> *; | |
| } | |
| -if class * extends @com.android.internal.annotations.WeaklyReferencedCallback ** | |
| -keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * { | |
| !synthetic <1> *; | |
| } | |
| # Understand the common @Keep annotation from various Android packages: | |
| # * android.support.annotation | |
| # * androidx.annotation | |
| # * com.android.internal.annotations | |
| -keep class **android**.annotation*.Keep | |
| -keep @**android**.annotation*.Keep class * { *; } | |
| -keepclasseswithmembers class * { | |
| @**android**.annotation*.Keep <methods>; | |
| } | |
| -keepclasseswithmembers class * { | |
| @**android**.annotation*.Keep <fields>; | |
| } | |
| -keepclasseswithmembers class * { | |
| @**android**.annotation*.Keep <init>(...); | |
| } | |
| # Keep Dalvik optimization annotations. These annotations are special in that | |
| # 1) we want them preserved for visibility with ART, but 2) they don't have | |
| # RUNTIME retention. These minimal keep rules ensure they're not stripped by R8. | |
| # TODO(b/215417388): Export this rule from the owning library, core-libart, | |
| # via export_proguard_flags_files. | |
| -keepclassmembers,allowshrinking,allowoptimization,allowobfuscation,allowaccessmodification class * { | |
| @dalvik.annotation.optimization.** *; | |
| } | |
| -include proguard_basic_keeps.flags | |
| -include proguard/kotlin.flags |