da0d73e580
Additional analysis revealed more edge cases where external library code was getting kept unnecessarily. Further refine the keep rules to avoid these cases. Now, we only apply keep globally for the `com.android.internal.annotations.VisibleForTesting` annotation. VisibleForTesting annotations defined externally (e.g., by androidx or guava) will *only* be respected in platform-defined packages. This helps trim unused code from deps like gRPC and Dagger, saving up to ~hundreds of KB per package that uses these libraries. Bug: 248580093 Test: m + verify exclusion of external test code (e.g., from dagger) Change-Id: Iab7559c08d3ae1ac74f18e3cf3a1b4828a3736cf
54 lines
2 KiB
Text
54 lines
2 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 members with the platform-defined @VisibleForTesting annotation.
|
|
-keep @com.android.internal.annotations.VisibleForTesting class *
|
|
-keepclassmembers class * {
|
|
@com.android.internal.annotations.VisibleForTesting *;
|
|
}
|
|
|
|
# Keep classes and members with non-platform @VisibleForTesting annotations, but
|
|
# only within platform-defined packages. This avoids keeping external, 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 android.**,com.android.**,com.google.android.**
|
|
-keepclassmembers class android.**,com.android.**,com.google.android.** {
|
|
@**.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
|