Skip to content

R8 resource shrinking path never runs aapt2 optimize (resource path shortening / sparse encoding have no effect with R8) #534

Description

@Dolfik1

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: Dolfik1@fa29d47

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions