android_library packs all resources instead of specific resource_files

オープン
#345 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
android

調査の方向性

まず rules/busybox.bzl の 110-125 行にある _make_resources_flag から始め、次に 681-689 行付近のリソース処理と、android_library が resource_files を aapt ビルドアクションに渡す方法を調べます。issue に記載された機能固有のターゲットを使って動作を検証します。完了の条件は、各ターゲットが共有ディレクトリ内のすべてのリソースではなく、一覧に記載されたリソースファイルだけをパッケージ化することです。

索引モデルが 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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_android のほかの issue

bazelbuild/rules_android の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。