Precise Resource Shrinker + `aapt2 optimize`
Background
Example of modifying rules_android to support precise resource shrinking and aapt2 optimize.
Changes
- Pull in
ResourceShrinkerClichanges- add
--precise-shrinkerflag - add arg for proguard map
- Add support for non-zip DEX files (used for feature modules, which is not included in this PR)
- Add support to dump
resources.cfgforaapt2 optimize(resource name obfuscation and value de-duping)
- add
- Add in
aapt2 optimizestep
@benjaminRomano This is still marked as draft. Did you still want to pursue it?
Furthermore, we've recently migrated all of the Android tool source code from Bazel to rules_android, so you no longer need to copy that file into this repository.
@ted-xie it'd be great to get this upstreamed. I've mostly created this as an example of what snapchat does. It's not production quality code as is but probably not too much effort to get it to that point. Feel free to work off this example if interested.
There's some configuration that should be exposed here since not all apps will be able to apply the full set of aapt2 optimizations without bug fixes. However there are some that can be enabled without modifications since they are relatively safe.
Btw is r8 maven dep now hosted directly in android rules now? That's been a point for me as I manually manage a custom version and have needed to regenerate the android tools zip in our bazel fork
It's not production quality code as is but probably not too much effort to get it to that point.
This would need extensive vetting internally; we'd need to check that it doesn't break existing apps, and there may or may not be a specific reason why aapt2 optimize doesn't already exist in our codebase. It looks like it would also inflate the action count for every Google app build, which is a metric we track closely for build health.
Btw is r8 maven dep now hosted directly in android rules now
The source of truth for R8 continues to be Maven.
I manually manage a custom version and have needed to regenerate the android tools zip in our bazel fork
The Android tools zip is no longer necessary for just loading R8 classes, since we migrated all the Bazel Android tools code (for things like CompatDexBuilder) to this repo. We still use the old android_tools zip for a couple deps that are not easily accessible on Maven (ex. databinding_exec).