xref: /aosp_15_r20/build/make/core/proguard.flags (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1# We have moved -dontobfuscate and -dontoptimize to the makefiles.
2# dex does not like code run through proguard optimize and preverify steps.
3# -dontoptimize
4-dontpreverify
5
6# Don't obfuscate. We only need dead code striping.
7# -dontobfuscate
8
9# Add this flag in your package's own configuration if it's needed.
10#-flattenpackagehierarchy
11
12# 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
18# 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
25# 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.
28# TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting
29# and com.google.common.annotations.VisibleForTesting use in platform code.
30-keep @**.VisibleForTesting class android.**,com.android.**,com.google.android.**
31-keepclassmembers class android.**,com.android.**,com.google.android.** {
32    @**.VisibleForTesting *;
33}
34
35# 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
41# 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
52# 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
57
58-keep @**android**.annotation*.Keep class * { *; }
59
60-keepclasseswithmembers class * {
61    @**android**.annotation*.Keep <methods>;
62}
63
64-keepclasseswithmembers class * {
65    @**android**.annotation*.Keep <fields>;
66}
67
68-keepclasseswithmembers class * {
69    @**android**.annotation*.Keep <init>(...);
70}
71
72# 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
81-include proguard_basic_keeps.flags
82-include proguard/kotlin.flags
83