Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precise Resource Shrinker + aapt2 optimize #217

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benjaminRomano
Copy link

Background

Example of modifying rules_android to support precise resource shrinking and aapt2 optimize.

Changes

  • Pull in ResourceShrinkerCli changes
    • add --precise-shrinker flag
    • 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.cfg for aapt2 optimize (resource name obfuscation and value de-duping)
  • Add in aapt2 optimize step

@ted-xie
Copy link
Contributor

ted-xie commented Oct 17, 2024

@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.

@benjaminRomano
Copy link
Author

@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.

@benjaminRomano
Copy link
Author

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

@ted-xie
Copy link
Contributor

ted-xie commented Oct 17, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants