From 97a9903c3e49731cb619f6992b99ac5d4a2df82e Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Tue, 2 Aug 2022 16:05:03 -0700 Subject: [PATCH] Refine VisibleForTesting proguard rules Both androidx (Jetpack) and com.google.common (Guava) define @VisibleForTesting annotations. These are used within these libraries for test purposes, but have also been adopted throughout the platform for platform-specific test code. Consequently, the current keep rules end up keeping not only platform test code, but also library test code that isn't actually needed. Refine these rules by restricting VisibleForTesting-annotated keep rules to include code *outside* of Jetpack/Guava. A longer term solution will involve migrating away from these annotations toward the platform-defined @TestApi and internal @VisibleForTesting variants. Note that platform code using the androidx* and c.g.common*-defined @VisibleForTesting annotations will still be kept. This saves about ~11MB of dex code from platform apps/services. Bug: 239961360 Test: m + validate dex changes for shrunk packages (SystemUI/Launcher) Change-Id: Icd70090e615b72a2cfb9ce8c43edb17cb46e05e2 --- core/proguard.flags | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/proguard.flags b/core/proguard.flags index aee5271744..53f63d8ea0 100644 --- a/core/proguard.flags +++ b/core/proguard.flags @@ -9,10 +9,15 @@ # 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 classes and methods that have @VisibleForTesting annotations, except in +# intermediate libraries that export those annotations (e.g., androidx, guava). +# This avoids keeping library-specific test code that isn't actually needed +# for platform testing. +# TODO(b/239961360): Migrate away from androidx.annotation.VisibleForTesting +# and com.google.common.annotations.VisibleForTesting use in platform code. +-keep @**.VisibleForTesting class !androidx.**,!com.google.common.**,* +-keepclassmembers class !androidx.**,!com.google.common.**,* { + @**.VisibleForTesting *; } # Keep rule for members that are needed solely to keep alive downstream weak