platform_build/core/proguard.flags
Jared Duke 7d0c90b51f Add keep rules for @KeepForWeakReference annotation
Ensure annotated fields are kept when treeshaking-related optimizations
are enabled. Note that this still allows field removal if tree shaking
reveals no references, but will avoid removal if there are references
that might impact downstream usage, e.g., weak references.

Bug: 227455445
Test: atest InternalAnnotationsTest
Change-Id: I59c6277c43b14c5de8154fa1eefad01f0702e413
2022-05-11 09:47:12 -07:00

44 lines
1.3 KiB
Text

# We have moved -dontobfuscate and -dontoptimize to the makefiles.
# dex does not like code run through proguard optimize and preverify steps.
# -dontoptimize
-dontpreverify
# Don't obfuscate. We only need dead code striping.
# -dontobfuscate
# Add this flag in your package's own configuration if it's needed.
#-flattenpackagehierarchy
# Keep classes and methods that have the guava @VisibleForTesting annotation
-keep @**.VisibleForTesting class *
-keepclassmembers class * {
@**.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>;
}
# 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>(...);
}
-include proguard_basic_keeps.flags