android_library packs all resources instead of specific resource_files

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

维护者通常 6 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
android

调研方向

从 rules/busybox.bzl 第 110-125 行的 _make_resources_flag 开始,然后检查第 681-689 行附近的资源处理逻辑,以及 android_library 如何将 resource_files 传递给 aapt 构建操作。使用 issue 中描述的功能专用 target 验证行为;完成的标准是每个 target 只打包其列出的资源文件,而不是共享目录中的所有资源。

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

描述

Observed behavior

We have one Bazel module for Icons used in different apps and we declare feature specific targets like so:

modules/iconography/BUILD:

android_library(
  name = "feature_x_icons",
  resource_files = [ "src/main/res/drawable/x_icon_1.xml", "src/main/res/drawable/x_icon_2.xml"]
)

android_library(
  name = "feature_y_icons",
  resource_files = [ "src/main/res/drawable/y_icon_a.xml", "src/main/res/drawable/y_icon_b.xml"]
)

What we've found is that different apps ended up packing all resources from modules/iconography/src/main/res/drawable despite only depending on very specific targets with specific resource_files referenced in them.

Environment

  • Bazel 9.0.0-pre.20250115.2
  • rules_android 0.6.2

Findings after Debugging

It turns out rules_android computes a set of common unique directories among all the resource_files and then passes those unique directories to aapt build action effectively packaging all resources from those dirs rather than specific resource_files user passed in the BUILD file.

_make_resources_flag:

https://github.com/bazelbuild/rules_android/blob/aed4306a9117bd0812ec80d4bc2cedadb1db6f94/rules/busybox.bzl#L110-L125

And

https://github.com/bazelbuild/rules_android/blob/aed4306a9117bd0812ec80d4bc2cedadb1db6f94/rules/busybox.bzl#L681-L689

In our case this resulted in 6MB-8MB excessive resources packaged into different apps that never needed nor referenced those resources.


Expected behavior

android_library() target should only package specific resource_files passed by user.

主要语言
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 摘要。