From 7d0c90b51fb21b2815f244958b4b26c320335f51 Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Mon, 9 May 2022 18:09:01 -0700 Subject: [PATCH] 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 --- core/proguard.flags | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/proguard.flags b/core/proguard.flags index 185275e858..aee5271744 100644 --- a/core/proguard.flags +++ b/core/proguard.flags @@ -15,6 +15,12 @@ @**.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 ; +} + # Understand the common @Keep annotation from various Android packages: # * android.support.annotation # * androidx.annotation