Google's Ship smarter keep rules: How library providers can unblock app-level DEX code optimization
Original post Ship smarter keep rules: How library providers can unblock app-level DEX code optimization
Article Summary
Breana Tate from Google reveals how library providers are unknowingly sabotaging Android app performance. Overly broad keep rules are blocking R8 optimization and forcing apps to ship bloated code that slows startup times and increases memory usage.
Google Play recently introduced DEX code optimization thresholds to improve app startup and reduce memory footprint. While these requirements target apps, meeting them depends heavily on the keep rules bundled by library providers. This guide shows SDK developers how to ship narrow, high-performance rules that unblock app-level optimization.
Key Takeaways
- Package-wide keep rules severely limit R8's whole-program optimization potential
- Jetpack Keep annotations (now in alpha) auto-generate rules from annotated reflection calls
- Codegen eliminates reflection crashes while enabling maximum R8 optimization
- Conditional keep rules preserve only features when corresponding adapters are present
- SDK Console deobfuscates stack traces without requiring keepnames rules
Library providers can dramatically improve downstream app performance by replacing broad keep rules with narrow, targeted rules that preserve only essential reflection and JNI entry points.
Continue reading
What This Article Covers
Breana Tate points out that library providers often ship broad rules like "-keep public class com.google.android.gms.** { *; }". These can override narrower, carefully scoped consumer rules from other dependencies, causing unnecessary bloat.
Google recommends testing critical user journeys in sample apps after turning on R8. From there, use the Android CLI analyze command to track what gets kept across library releases, including methods and classes, so regressions don't slip through.
When rules ship directly in consumer keep files rather than in documentation, apps avoid piling up outdated legacy rules across version upgrades. This keeps long-term app bloat in check.
This page summarizes “Ship smarter keep rules: How library providers can unblock app-level DEX code optimization” by Google, published Nov 17, 2026. All credit for the original work goes to the authors.