Log date · Tue
How do you use R8 Configuration Analyzer to audit keep rules?
The analyzer shows how keep rules restrict code; identify broad rules, narrow them and test the release build.
The answer: scores and actual output
R8 Configuration Analyzer identifies keep rules that restrict shrinking, optimization and renaming, but its scores are not measures of resistance to analysis. We built the same sample twice with R8 8.3.37: a narrow rule renamed Pricing, its field and its method; a broad rule retained all three names. Both printed DEMO-PLAN120, and the string remained in the bytecode.
| Question | Result |
|---|---|
| Narrow rule | Pricing → a.a; basePrice and quote → a. |
| Broad rule | Class, field and method retain their names. |
| Runtime result | Both print DEMO-PLAN120. |
| Scores | No analyzer score was generated. |
What the case study scores mean
On August 18, 2026 (the blog’s Pacific-time date), the Android Developers Blog published a Tinder case study. The team traced a wide rule affecting many dependencies to an internal library. After refinement, the post reported R8 scores rising from 28% to 50%, alongside improvements in cold starts and download size. [1] Those are results for that app, not a promise for another build.
The report gives separate shrinking, optimization and obfuscation scores: the share of code available for each operation. The obfuscation score concerns eligibility to rename classes, fields and methods. [2] It does not guarantee that each eligible item is renamed, and it says nothing about string secrecy or recovery effort. Inspect which items each rule affects and where it came from, including merged library consumer rules.
Each score answers a different question: shrinking concerns what may be removed, optimization what may be transformed, and obfuscation what may be renamed. A rule can constrain more than one operation, so do not focus on one number alone. When comparing reports, check that the variant and dependencies have not changed as well.
How two rules changed names
We wrote two Java classes, compiled them with javac 17.0.19 and used R8 8.3.37 to produce classfiles. Both variants disable optimization to isolate names. This illustrates rule effects; it is not a test of Configuration Analyzer, AGP 9.3, DEX or an Android release package. Both keep the entry point; the broad variant additionally keeps every Pricing member.
-keep public class demo.Main { public static void main(java.lang.String[]); }
-dontoptimize
# Broad variant adds:
-keep class demo.Pricing { *; }The narrow mapping shows the renamed class and two members. The broad mapping retains the class name, and javap shows the field and method retained too. Both artifacts ran the same no-argument path; that is not a substitute for tests covering dynamic calls.
demo.Pricing -> a.a:
# {"id":"sourceFile","fileName":"Pricing.java"}
int basePrice -> a
1:1:void <init>():0:0 -> <init>
1:1:java.lang.String quote(int):0:0 -> aBoth bytecode outputs retain DEMO-PLAN and the numbers 120 and 17 used in the calculation. Short names remove semantic clues but do not automatically conceal constants. Optimization and reachability change actual results; do not ship a shared privileged secret in the client and rely on renaming to protect it.
Recommendations for acting on the report
Sort rules by impact, then identify the dynamic entry points each one actually protects. The following are engineering recommendations, not benefits measured by our experiment. Without modifiers, -keep prevents optimization of matched items; options and modifiers differ in their effects on shrinking and renaming. [3]
| Finding | Next step |
|---|---|
| Broad app rule | Identify exact classes and members needed for reflection, serialization or JNI; narrow gradually. |
| Library consumer rule | Trace its source and affected items; provide the report to its maintainer and validate any replacement. |
| Overlapping or unused rules | Check actual matches and dynamic dependencies before removing redundancy. |
| Score rises | Rebuild and test critical paths; measure size and performance separately. |
Do not simply delete a broad rule: it may have masked missing reflection rules. Add runtime tests for affected features, then validate the release build. For an external library, Android recommends contacting its maintainer; default AGP rules should not be changed casually. [2]
When a rule comes from a library, record its version and the source shown in the report, then reproduce the affected feature. A library upgrade can change the rule and its scope. Whoever maintains the rule, retain regression tests so future upgrades expose runtime failures.
Run it on your own app
For a project using AGP 9.3.0 or later, run the standalone task first; replace app and Release with your module and build variant. The standalone task does not generate an APK or Bundle. A full R8 release build also writes a report in the mapping directory. [2]
./gradlew :app:analyzeReleaseR8Config
# app/build/reports/r8/r8-config-analyzer-release.html
./gradlew :app:assembleRelease
# app/build/outputs/mapping/release/configanalyzer.htmlRecord the build variant, dependency versions and all three scores. Open rule details to check origins and affected members. Change one group of rules at a time, regenerate the report, and test affected paths such as sign-in, serialization, reflection and native interfaces in the actual release package. Store the matching mapping privately for crash retracing. CI can track score trends, but interpret them alongside build changes and test results rather than treating a threshold as a security verdict.
Your checklist
- Generate the analyzer report for the target release variant.
- Inspect the highest-impact rules and their origins.
- Identify classes and members required by reflection, serialization and JNI.
- Narrow rules incrementally and test the release build.
- Track scores, performance and size; store the matching mapping privately.
Primary sources
- Android Developers Blog: Tinder cuts app cold starts by 47% with new R8 Configuration Analyzer · Source date 2026-08-18 · Checked 2026-10-12
- Android: Use R8 Configuration Analyzer · Checked 2026-11-11
- Android: Add keep rules · Checked 2026-11-11