Google

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

Critical Insight

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

Problem

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.

Solution

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.

Impact

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.

The article includes a surprising pattern many libraries get wrong when handling Google Play Services dependencies that creates unnecessary bloat across the entire ecosystem.

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.

Read the original on developer.android.com (opens in new tab)

AI tools for Android

Browse all AI tools →