Mastering R8 Configuration: A Practical Guide to Optimization and Debugging
Status: Accepted
Enabling R8 is one of the most effective steps you can take to shrink, obfuscate, and optimize your Android app. But what happens when R8's optimizations lead to a runtime crash like ClassNotFoundException or NoSuchMethodError? For many developers, the immediate fix is a broad, "catch-all" keep rule—or worse, disabling R8 altogether.
This session provides a practical, step-by-step guide to mastering R8's configuration, not just enabling it. We'll start with a sample app, enable R8, and intentionally trigger a common crash (e.g., from reflection).
You'll learn to:
- Use R8's tools like retrace to de-obfuscate the stack trace and find the true root cause.
- Analyze R8's configuration path and output files (like configuration.txt) to understand why R8 removed the specific class or method.
- Write a specific, narrow keep rule that fixes the bug without unnecessarily bloating your app.
This session will give you the tools and confidence to diagnose any R8-related issue and write precise, efficient keep rules.
Attendees will leave this session knowing how to:
- Implement R8 in a new or existing Android project correctly.
- Debug minified apps by de-obfuscating stack traces to find the real source of a crash.
- Analyze R8's build outputs to understand what code was kept, removed, and why.
- Identify the root cause of common R8 issues, especially those related to reflection, serialization, or JNI.
- Write effective, narrow keep rules that target the specific problem instead of using broad rules that harm optimization.
- Verify R8's configuration to ensure your rules are being applied as expected and are having the intended effect.

