Status Update
Comments
cc...@google.com <cc...@google.com> #2
Currently this is infeasible, since the R8 metadata doesn't end up in the APK by design - we don't want to waste space on device.
We have thought about alternative ways to get massively minified versions of metadata into the final apk so profilers (or things like profileverifier) could have access, but it's a nontrivial project.
li...@pinterest.com <li...@pinterest.com> #3
cc...@google.com <cc...@google.com> #4
Starting in AGP 8.8, AGP/R8 will output metadata into your bundle that can be used to check if it was successful in dex layout optimization.
After building your bundle:
./gradlew app:bundleRelease
You can check the metadata (replace with the path to your .aab):
unzip -j -o build/outputs/bundle/release/app-release.aab BUNDLE-METADATA/com.android.tools/r8.json && jq .dexFiles r8.json
This will tell you each dex file that R8 created, and whether it contains startup classes. In a simple test app without dex layout optimization I see the following:
inflating: r8.json
[
{
"checksum": "f0b4b0ddb295812607f44efe03cf7a830056ccfddbdb81db3760d2281940e951",
"startup": false
}
]
Then also get the shas for all your dex files from the bundle itself:
unzip -o ../../out/androidx/benchmark/integration-tests/macrobenchmark-target/build/outputs/bundle/release/macrobenchmark-target-release.aab */dex/*.dex && sha256sum */dex/*
In my test app, this outputs:
Archive: ../../out/androidx/benchmark/integration-tests/macrobenchmark-target/build/outputs/bundle/release/macrobenchmark-target-release.aab
inflating: base/dex/classes.dex
f0b4b0ddb295812607f44efe03cf7a830056ccfddbdb81db3760d2281940e951 base/dex/classes.dex
Once you've got those outputs, there's three things to check:
- The R8 metadata file is present in your AAB If not present, you either need to update AGP or enable R8. (This isn't necessary for startup profiles to work, just for this checking workflow)
- a number of
"startup": true
dex files If not seen, you likely need to enable startup dex layout, and ensure that your startup profile isn't obfuscated - dex shas from the metadata should match up with those from the bundle If the shas dont match, you may have some compilation step interfering with R8's ability to output dex files
Over to Ben to consider how to put this in DAC
be...@google.com <be...@google.com> #5
ch...@google.com <ch...@google.com> #6
If we need to make the R8 build metadata more accessible, we could consider if AGP should write the build metadata to build/outputs/mapping/release/metadata.json
. AGP already stores various R8 artifacts in this build directory, such as configuration.txt
and mapping.txt
. That way when developers build a normal release build (assembleRelease
) they could simply inspect the metadata.json
file in the build
directory.
Description
Can this data be exposed as part of [ProfileVerifier](