bazelbuild / bazelbuild/rules_android
R8 resource shrinking path never runs aapt2 optimize (resource path shortening / sparse encoding have no effect with R8)
- Dominant language
- Java
- Stars
- 203
- Forks
- 95
- PR merge metrics
- No merged PRs in 30d
Description
The legacy ProGuard pipeline runs `aapt2 optimize` after resource shrinking (see _process_optimize in rules/android_binary/impl.bzl). The R8 resource shrinking path (process_resource_shrinking_r8 in rules/android_binary/r8.bzl) stops after producing the shrunk resource APK and never invokes optimize.
As a result, `//rules/flags:experimental_android_resource_path_shortening` and the `enable_sparse_encoding` attribute silently do nothing when R8 is used.
There's no error or warning — they're just ignored, which is easy to miss when migrating and comparing APK sizes against a Gradle build (AGP applies these optimizations as part of its R8 pipeline). We confirmed on our app that with the flag set, resource paths in the APK stay unshortened on the R8 path.
We're running a patch that wires _resources.optimize into the R8 path after the shrinking step, after which path shortening works as expected: https://github.com/Dolfik1/rules_android/commit/fa29d470bbe9f609c83a0993259a29a8e6994371
Notes:
- _resources.optimize already gates itself on the path-shortening flag, compilation mode and ACLs, so the added call is a no-op unless those are enabled — behavior for anyone not using these features is unchanged.
- Resource name obfuscation is left disabled: it needs the resource optimization config that the R8 resource shrinker doesn't produce (resource_optimization_config = None). Could be a follow-up.
Happy to send a PR with tests if this looks right.
Contributor guide
Research direction
Read rules/android_binary/r8.bzl, then compare process_resource_shrinking_r8 with _process_optimize in rules/android_binary/impl.bzl. Review the referenced patch and add tests covering the R8 path with resource path shortening or sparse encoding enabled. Done means those options take effect on the R8 resource APK without changing behavior when they are disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100