After you enable app optimization, check that your app is working as intended and that the R8 configuration is doing what you expect. The general steps are as follows:
- Test your app's critical user journeys (CUJs): For example, make sure that users can sign in and do other important tasks.
- Measure performance gains using benchmarks: Benchmark your app before and after enabling app optimization.
If you find issues, R8 provides tools to help you troubleshoot. If you're unable to solve an issue with R8, file a bug.
General tips
Issues with R8 are often unique to your app, but here are some general tips to make debugging easier:
- Temporarily turn off obfuscation: R8 obfuscates code as part of its
optimization process. Obfuscation usually isn't the cause of errors, but
obfuscation makes errors more difficult to debug. Add the
‑dontobfuscate
and‑dontoptimize
flags to the keep rules file to help you pinpoint problematic code. Check for reflection: If you run into a no such element exception such as
Caused by: java.util.NoSuchElementException: Collection contains no element matching the predicate in the stack trace
,the exception usually means the field in question is being used through reflection and you have to add a keep rule.
Inspect bytecode: Most R8 issues require bytecode inspection, which you can do with tools such as the APK Analyzer.
Check which rules are applied
To output a full report of all the rules that R8 applies when building your
project, include the following in your app's module
proguard‑rules.pro
file:
-printconfiguration <output-dir>/<report-name>.txt
You can specify any path and filename. If you don't specify a path or filename,
R8 outputs the rules report at <module-name>/build/outputs/mapping/<build-type>/configuration.txt
.
Understand why code was kept
If you see kept code that you expected to be removed, use the configuration
option ‑whyareyoukeeping
to help understand why the code was
kept. R8 outputs a path from the kept code to one of your app's entry
points. For more information, see the
‑whyareyoukeeping
documentation in the Proguard manual.
Recover the original stack trace
Code processed by R8 is changed in various ways so that the stack trace no longer refers to the original code. For example, line numbers and the names of classes and methods can change. To recover the original stack trace, R8 provides the retrace command-line tool, which is bundled with the command-line tools package.
To use retrace, give it a mapping file and a stack trace file. The mapping
file, called mapping.txt
, is automatically bundled with your Android App
Bundle (AAB). For more details, see the retrace documentation and the Play
Console Help Center article about how to de‑obfuscate crash stack
traces.