bazelbuild / bazelbuild/rules_android

android_library packs all resources instead of specific resource_files

Open
#345 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
203
Forks
95
PR merge metrics
No merged PRs in 30d

Description

## Observed behavior

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

`modules/iconography/BUILD`:

```js
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.