Google tells Android library makers to narrow their R8 keep rules
Android's developer team says broad rules bundled in libraries stop apps from shrinking code, and sets out how library providers can fix them.
EDITOR | Tuesday 17 November 2026 | World

Google's Android developer team has published guidance for library providers on keep rules. These are instructions that tell R8, Android's app optimizer, which code it must not remove or rename. R8 improves performance by removing unused code and optimizing and obfuscating the rest.
The post says Google Play recently announced new DEX code optimization thresholds for apps and games, and that meeting them is a shared job. R8 can only work within the rules it is given, including those bundled in the libraries an app uses.
Breana Tate, a Developer Relations Engineer, writes that package-wide keep rules severely limit R8. Such rules force apps to carry unused code, which slows startup and raises download size, memory use and ANR (app not responding) rates.
She recommends testing narrow rules in a sample app, running the R8 Configuration Analyzer and the Android CLI analyze command, and using code generation instead of reflection where possible. Where reflection is needed, rules should name only the entry points. Jetpack Keep annotations, now in alpha, can generate rules from the source.
Libraries should also ship rules inside the library rather than in documentation, and should not block renaming just to read stack traces, because Crashlytics, Play Console and Android Studio can deobfuscate them.