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

未关闭
#534 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 6 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
android, java

调研方向

阅读 rules/android_binary/r8.bzl,然后比较 rules/android_binary/impl.bzl 中的 process_resource_shrinking_r8 和 _process_optimize。审查所引用的补丁,并添加涵盖启用资源路径缩短或稀疏编码时 R8 路径的测试。完成的标准是这些选项会在 R8 资源 APK 上生效,同时在禁用这些选项时行为不发生变化。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
205
派生
113
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bazelbuild/rules_android 的其他 Issue

查看 bazelbuild/rules_android 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。