The “keep radius” of a keep rule refers to the negative impact that the rule has on the final application.
R8 provides a tool to analyze and visualize this keep radius. This helps developers:
Note: This feature is currently experimental and requires R8 version 9.2.14-dev or higher.
R8 supports outputting a Configuration Analysis Report as an HTML file.
To generate the HTML report from a Gradle build, pass the com.android.tools.r8.dumpkeepradiushtmltodirectory system property.
See Replacing R8 in AGP for instructions on how to update the R8 version in your build.
./gradlew assembleRelease \ --no-daemon \ -Dcom.android.tools.r8.dumpkeepradiushtmltodirectory=<output_directory>
Example:
./gradlew assembleRelease \ --no-daemon \ -Dcom.android.tools.r8.dumpkeepradiushtmltodirectory=/tmp/blastradius
For builds within the Android Platform, set the R8_DUMP_BLAST_RADIUS environment variable to true.
R8_DUMP_BLAST_RADIUS=true m
This will generate an r8blastradius.pb file for each R8 build target within out/soong/.intermediates.
The raw .pb file can be converted into an interactive HTML report using the BlastRadiusHtmlReportGenerator.
Use the following command to convert a specific .pb file to HTML:
java -cp r8.jar com.android.tools.r8.blastradius.BlastRadiusHtmlReportGenerator \ <path_to_input_pb> <path_to_output_html>
Example:
java -cp r8.jar com.android.tools.r8.blastradius.BlastRadiusHtmlReportGenerator \ /tmp/blastradius/blastradius.pb /tmp/blastradius/report.html
If you have multiple blast radius files (e.g., from an Android Platform build), you can generate a summary report for the directory:
java -cp prebuilts/r8/r8.jar com.android.tools.r8.blastradius.BlastRadiusHtmlReportGenerator \ <path_to_input_directory> <path_to_output_directory>
Example:
java -cp prebuilts/r8/r8.jar com.android.tools.r8.blastradius.BlastRadiusHtmlReportGenerator \ out/soong/.intermediates /tmp/blastradiusreport
This will scan the input directory for .pb files and generate an HTML report in the output directory.