Android guidance: Narrow library keep rules to unlock app-level DEX optimization
Brief
Android’s guidance explains how library providers can help dependent apps pass Google Play’s DEX optimization thresholds without sacrificing stability.
Audit and narrow consumer rules
- Test optimized builds and critical user journeys in a sample app; use the R8 Configuration Analyzer and Android CLI’s analyze command to inspect rules and compare optimization across releases.
- Keep only the classes or entry points actually accessed through reflection. Broad or package-wide rules can preserve unused code and limit app-level optimization.
Use alternatives and ship rules with libraries
- Prefer code generation over reflection where practical; for reflection, JNI, optional dependencies, and mediation adapters, use narrowly scoped or conditional rules.
- Bundle consumer rules in the AAR or JAR rather than relying on documentation, and use deobfuscation tools or uploaded mapping files instead of keepnames to read stack traces.
Generated by AI from the original article. Check the source for full details.