blob: 5148e56407b7c554747869b0e25f3cf9f2564544 [file] [log] [blame]
Ying Wang7311a342013-08-21 18:32:49 -07001# We have moved -dontobfuscate and -dontoptimize to the makefiles.
Ying Wang3b2bdf12010-02-01 09:51:23 -08002# dex does not like code run through proguard optimize and preverify steps.
Ying Wang7311a342013-08-21 18:32:49 -07003# -dontoptimize
Ying Wang3b2bdf12010-02-01 09:51:23 -08004-dontpreverify
5
6# Don't obfuscate. We only need dead code striping.
Ying Wang7311a342013-08-21 18:32:49 -07007# -dontobfuscate
Ying Wang3b2bdf12010-02-01 09:51:23 -08008
9# Add this flag in your package's own configuration if it's needed.
10#-flattenpackagehierarchy
11
Jared Dukeda0d73e2023-02-01 10:27:04 -080012# Keep classes and members with the platform-defined @VisibleForTesting annotation.
13-keep @com.android.internal.annotations.VisibleForTesting class *
14-keepclassmembers class * {
15 @com.android.internal.annotations.VisibleForTesting *;
16}
17
Yifei Zhangf0581e62024-02-09 00:14:25 +000018# Keep classes and members with platform @TestApi annotations, similar to
19# @VisibleForTesting.
20-keep @android.annotation.TestApi class *
21-keepclassmembers class * {
22 @android.annotation.TestApi *;
23}
24
Jared Dukeda0d73e2023-02-01 10:27:04 -080025# Keep classes and members with non-platform @VisibleForTesting annotations, but
26# only within platform-defined packages. This avoids keeping external, library-specific
27# test code that isn't actually needed for platform testing.
Jared Duke97a99032022-08-02 16:05:03 -070028# TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting
29# and com.google.common.annotations.VisibleForTesting use in platform code.
Jared Dukeda0d73e2023-02-01 10:27:04 -080030-keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.**
31-keepclassmembers class android.**,com.android.**,com.google.android.** {
Jared Duke97a99032022-08-02 16:05:03 -070032 @**.VisibleForTesting *;
Ying Wang38cdd442013-05-30 10:45:46 -070033}
Ying Wang3b2bdf12010-02-01 09:51:23 -080034
Jared Duke7d0c90b2022-05-09 18:09:01 -070035# Keep rule for members that are needed solely to keep alive downstream weak
36# references, and could otherwise be removed after tree shaking optimizations.
37-keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * {
38 @com.android.internal.annotations.KeepForWeakReference <fields>;
39}
40
Jared Duke7bed8162024-07-26 22:34:50 +000041# Needed to ensure callback field references are kept in their respective
42# owning classes when the downstream callback registrars only store weak refs.
43-if @com.android.internal.annotations.WeaklyReferencedCallback class *
44-keepclassmembers,allowaccessmodification class * {
45 <1> *;
46}
47-if class * extends @com.android.internal.annotations.WeaklyReferencedCallback **
48-keepclassmembers,allowaccessmodification class * {
49 <1> *;
50}
51
Jared Duke4bd749b2021-12-14 15:28:33 -080052# Understand the common @Keep annotation from various Android packages:
53# * android.support.annotation
54# * androidx.annotation
55# * com.android.internal.annotations
56-keep class **android**.annotation*.Keep
Colin Cross38b48de2019-03-26 09:48:28 -070057
Jared Duke4bd749b2021-12-14 15:28:33 -080058-keep @**android**.annotation*.Keep class * { *; }
Colin Cross38b48de2019-03-26 09:48:28 -070059
60-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080061 @**android**.annotation*.Keep <methods>;
Colin Cross38b48de2019-03-26 09:48:28 -070062}
63
64-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080065 @**android**.annotation*.Keep <fields>;
Colin Cross38b48de2019-03-26 09:48:28 -070066}
67
68-keepclasseswithmembers class * {
Jared Duke4bd749b2021-12-14 15:28:33 -080069 @**android**.annotation*.Keep <init>(...);
Colin Cross38b48de2019-03-26 09:48:28 -070070}
71
Jared Dukecb3505c2023-09-01 21:27:30 +000072# Keep Dalvik optimization annotations. These annotations are special in that
73# 1) we want them preserved for visibility with ART, but 2) they don't have
74# RUNTIME retention. These minimal keep rules ensure they're not stripped by R8.
75# TODO(b/215417388): Export this rule from the owning library, core-libart,
76# via export_proguard_flags_files.
77-keepclassmembers,allowshrinking,allowoptimization,allowobfuscation,allowaccessmodification class * {
78 @dalvik.annotation.optimization.** *;
79}
80
Ying Wang57453512013-05-17 10:02:00 -070081-include proguard_basic_keeps.flags
Yifei Zhange6d99642023-11-02 17:23:07 -070082-include proguard/kotlin.flags