blob: 76655ca6aa6f1886d2f1e2866ca48bce3c615db3 [file] [log] [blame]
Jared Dukeda0d73e2023-02-01 10:27:04 -08001# Keep classes and members with the platform-defined @VisibleForTesting annotation.
2-keep @com.android.internal.annotations.VisibleForTesting class *
3-keepclassmembers class * {
4 @com.android.internal.annotations.VisibleForTesting *;
5}
6
Yifei Zhangf0581e62024-02-09 00:14:25 +00007# Keep classes and members with platform @TestApi annotations, similar to
8# @VisibleForTesting.
9-keep @android.annotation.TestApi class *
10-keepclassmembers class * {
11 @android.annotation.TestApi *;
12}
13
Jared Dukeda0d73e2023-02-01 10:27:04 -080014# Keep classes and members with non-platform @VisibleForTesting annotations, but
15# only within platform-defined packages. This avoids keeping external, library-specific
16# test code that isn't actually needed for platform testing.
Jared Duke97a99032022-08-02 16:05:03 -070017# TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting
18# and com.google.common.annotations.VisibleForTesting use in platform code.
Jared Dukeda0d73e2023-02-01 10:27:04 -080019-keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.**
20-keepclassmembers class android.**,com.android.**,com.google.android.** {
Jared Duke97a99032022-08-02 16:05:03 -070021 @**.VisibleForTesting *;
Ying Wang38cdd442013-05-30 10:45:46 -070022}
Ying Wang3b2bdf12010-02-01 09:51:23 -080023
Jared Duke7d0c90b2022-05-09 18:09:01 -070024# Keep rule for members that are needed solely to keep alive downstream weak
25# references, and could otherwise be removed after tree shaking optimizations.
26-keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * {
27 @com.android.internal.annotations.KeepForWeakReference <fields>;
28}
29
Jared Duke7bed8162024-07-26 22:34:50 +000030# Needed to ensure callback field references are kept in their respective
31# owning classes when the downstream callback registrars only store weak refs.
32-if @com.android.internal.annotations.WeaklyReferencedCallback class *
Jared Duke71bff6a2024-12-27 23:20:03 +000033-keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * {
34 !synthetic <1> *;
Jared Duke7bed8162024-07-26 22:34:50 +000035}
36-if class * extends @com.android.internal.annotations.WeaklyReferencedCallback **
Jared Duke71bff6a2024-12-27 23:20:03 +000037-keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * {
38 !synthetic <1> *;
Jared Duke7bed8162024-07-26 22:34:50 +000039}
40
Jared Duke4bd749b2021-12-14 15:28:33 -080041# Understand the common @Keep annotation from various Android packages:
42# * android.support.annotation
43# * androidx.annotation
44# * com.android.internal.annotations
45-keep class **android**.annotation*.Keep
Colin Cross38b48de2019-03-26 09:48:28 -070046
Jared Duke4bd749b2021-12-14 15:28:33 -080047-keep @**android**.annotation*.Keep class * { *; }
Colin Cross38b48de2019-03-26 09:48:28 -070048
49-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080050 @**android**.annotation*.Keep <methods>;
Colin Cross38b48de2019-03-26 09:48:28 -070051}
52
53-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080054 @**android**.annotation*.Keep <fields>;
Colin Cross38b48de2019-03-26 09:48:28 -070055}
56
57-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080058 @**android**.annotation*.Keep <init>(...);
Colin Cross38b48de2019-03-26 09:48:28 -070059}
60
Jared Dukecb3505c2023-09-01 21:27:30 +000061# Keep Dalvik optimization annotations. These annotations are special in that
62# 1) we want them preserved for visibility with ART, but 2) they don't have
63# RUNTIME retention. These minimal keep rules ensure they're not stripped by R8.
64# TODO(b/215417388): Export this rule from the owning library, core-libart,
65# via export_proguard_flags_files.
66-keepclassmembers,allowshrinking,allowoptimization,allowobfuscation,allowaccessmodification class * {
67 @dalvik.annotation.optimization.** *;
68}
69
Ying Wang57453512013-05-17 10:02:00 -070070-include proguard_basic_keeps.flags
Yifei Zhange6d99642023-11-02 17:23:07 -070071-include proguard/kotlin.flags