android_library packs all resources instead of specific resource_files

Đang mở
#345 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
android
Lĩnh vực
build-system, mobile

Hướng nghiên cứu

Bắt đầu với _make_resources_flag trong rules/busybox.bzl, các dòng 110-125, sau đó kiểm tra cách xử lý resource quanh các dòng 681-689 và cách android_library truyền resource_files cho hành động build của aapt. Xác minh hành vi bằng các target dành riêng cho tính năng được mô tả trong issue; hoàn tất có nghĩa là mỗi target chỉ đóng gói các tệp resource được liệt kê cho nó, thay vì mọi resource trong các thư mục dùng chung.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
205
Fork
113
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bazelbuild/rules_android

Tất cả issue của bazelbuild/rules_android

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.