xref: /aosp_15_r20/build/make/core/proguard.flags (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1*9e94795aSAndroid Build Coastguard Worker# We have moved -dontobfuscate and -dontoptimize to the makefiles.
2*9e94795aSAndroid Build Coastguard Worker# dex does not like code run through proguard optimize and preverify steps.
3*9e94795aSAndroid Build Coastguard Worker# -dontoptimize
4*9e94795aSAndroid Build Coastguard Worker-dontpreverify
5*9e94795aSAndroid Build Coastguard Worker
6*9e94795aSAndroid Build Coastguard Worker# Don't obfuscate. We only need dead code striping.
7*9e94795aSAndroid Build Coastguard Worker# -dontobfuscate
8*9e94795aSAndroid Build Coastguard Worker
9*9e94795aSAndroid Build Coastguard Worker# Add this flag in your package's own configuration if it's needed.
10*9e94795aSAndroid Build Coastguard Worker#-flattenpackagehierarchy
11*9e94795aSAndroid Build Coastguard Worker
12*9e94795aSAndroid Build Coastguard Worker# Keep classes and members with the platform-defined @VisibleForTesting annotation.
13*9e94795aSAndroid Build Coastguard Worker-keep @com.android.internal.annotations.VisibleForTesting class *
14*9e94795aSAndroid Build Coastguard Worker-keepclassmembers class * {
15*9e94795aSAndroid Build Coastguard Worker    @com.android.internal.annotations.VisibleForTesting *;
16*9e94795aSAndroid Build Coastguard Worker}
17*9e94795aSAndroid Build Coastguard Worker
18*9e94795aSAndroid Build Coastguard Worker# Keep classes and members with platform @TestApi annotations, similar to
19*9e94795aSAndroid Build Coastguard Worker# @VisibleForTesting.
20*9e94795aSAndroid Build Coastguard Worker-keep @android.annotation.TestApi class *
21*9e94795aSAndroid Build Coastguard Worker-keepclassmembers class * {
22*9e94795aSAndroid Build Coastguard Worker    @android.annotation.TestApi *;
23*9e94795aSAndroid Build Coastguard Worker}
24*9e94795aSAndroid Build Coastguard Worker
25*9e94795aSAndroid Build Coastguard Worker# Keep classes and members with non-platform @VisibleForTesting annotations, but
26*9e94795aSAndroid Build Coastguard Worker# only within platform-defined packages. This avoids keeping external, library-specific
27*9e94795aSAndroid Build Coastguard Worker# test code that isn't actually needed for platform testing.
28*9e94795aSAndroid Build Coastguard Worker# TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting
29*9e94795aSAndroid Build Coastguard Worker# and com.google.common.annotations.VisibleForTesting use in platform code.
30*9e94795aSAndroid Build Coastguard Worker-keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.**
31*9e94795aSAndroid Build Coastguard Worker-keepclassmembers class android.**,com.android.**,com.google.android.** {
32*9e94795aSAndroid Build Coastguard Worker    @**.VisibleForTesting *;
33*9e94795aSAndroid Build Coastguard Worker}
34*9e94795aSAndroid Build Coastguard Worker
35*9e94795aSAndroid Build Coastguard Worker# Keep rule for members that are needed solely to keep alive downstream weak
36*9e94795aSAndroid Build Coastguard Worker# references, and could otherwise be removed after tree shaking optimizations.
37*9e94795aSAndroid Build Coastguard Worker-keepclassmembers,allowaccessmodification,allowobfuscation,allowshrinking class * {
38*9e94795aSAndroid Build Coastguard Worker  @com.android.internal.annotations.KeepForWeakReference <fields>;
39*9e94795aSAndroid Build Coastguard Worker}
40*9e94795aSAndroid Build Coastguard Worker
41*9e94795aSAndroid Build Coastguard Worker# Needed to ensure callback field references are kept in their respective
42*9e94795aSAndroid Build Coastguard Worker# owning classes when the downstream callback registrars only store weak refs.
43*9e94795aSAndroid Build Coastguard Worker-if @com.android.internal.annotations.WeaklyReferencedCallback class *
44*9e94795aSAndroid Build Coastguard Worker-keepclassmembers,allowaccessmodification class * {
45*9e94795aSAndroid Build Coastguard Worker  <1> *;
46*9e94795aSAndroid Build Coastguard Worker}
47*9e94795aSAndroid Build Coastguard Worker-if class * extends @com.android.internal.annotations.WeaklyReferencedCallback **
48*9e94795aSAndroid Build Coastguard Worker-keepclassmembers,allowaccessmodification class * {
49*9e94795aSAndroid Build Coastguard Worker  <1> *;
50*9e94795aSAndroid Build Coastguard Worker}
51*9e94795aSAndroid Build Coastguard Worker
52*9e94795aSAndroid Build Coastguard Worker# Understand the common @Keep annotation from various Android packages:
53*9e94795aSAndroid Build Coastguard Worker#  * android.support.annotation
54*9e94795aSAndroid Build Coastguard Worker#  * androidx.annotation
55*9e94795aSAndroid Build Coastguard Worker#  * com.android.internal.annotations
56*9e94795aSAndroid Build Coastguard Worker-keep class **android**.annotation*.Keep
57*9e94795aSAndroid Build Coastguard Worker
58*9e94795aSAndroid Build Coastguard Worker-keep @**android**.annotation*.Keep class * { *; }
59*9e94795aSAndroid Build Coastguard Worker
60*9e94795aSAndroid Build Coastguard Worker-keepclasseswithmembers class * {
61*9e94795aSAndroid Build Coastguard Worker    @**android**.annotation*.Keep <methods>;
62*9e94795aSAndroid Build Coastguard Worker}
63*9e94795aSAndroid Build Coastguard Worker
64*9e94795aSAndroid Build Coastguard Worker-keepclasseswithmembers class * {
65*9e94795aSAndroid Build Coastguard Worker    @**android**.annotation*.Keep <fields>;
66*9e94795aSAndroid Build Coastguard Worker}
67*9e94795aSAndroid Build Coastguard Worker
68*9e94795aSAndroid Build Coastguard Worker-keepclasseswithmembers class * {
69*9e94795aSAndroid Build Coastguard Worker    @**android**.annotation*.Keep <init>(...);
70*9e94795aSAndroid Build Coastguard Worker}
71*9e94795aSAndroid Build Coastguard Worker
72*9e94795aSAndroid Build Coastguard Worker# Keep Dalvik optimization annotations. These annotations are special in that
73*9e94795aSAndroid Build Coastguard Worker# 1) we want them preserved for visibility with ART, but 2) they don't have
74*9e94795aSAndroid Build Coastguard Worker# RUNTIME retention. These minimal keep rules ensure they're not stripped by R8.
75*9e94795aSAndroid Build Coastguard Worker# TODO(b/215417388): Export this rule from the owning library, core-libart,
76*9e94795aSAndroid Build Coastguard Worker# via export_proguard_flags_files.
77*9e94795aSAndroid Build Coastguard Worker-keepclassmembers,allowshrinking,allowoptimization,allowobfuscation,allowaccessmodification class * {
78*9e94795aSAndroid Build Coastguard Worker    @dalvik.annotation.optimization.** *;
79*9e94795aSAndroid Build Coastguard Worker}
80*9e94795aSAndroid Build Coastguard Worker
81*9e94795aSAndroid Build Coastguard Worker-include proguard_basic_keeps.flags
82*9e94795aSAndroid Build Coastguard Worker-include proguard/kotlin.flags
83