Skip to content

Bazel 8 migration - Resources Conflict Handling#206

Open
edwin-grabtaxi wants to merge 1 commit intomigration/bazel_8_main_branchfrom
migration/bazel_8_res_conflict_handling
Open

Bazel 8 migration - Resources Conflict Handling#206
edwin-grabtaxi wants to merge 1 commit intomigration/bazel_8_main_branchfrom
migration/bazel_8_res_conflict_handling

Conversation

@edwin-grabtaxi
Copy link
Collaborator

@edwin-grabtaxi edwin-grabtaxi commented Feb 19, 2026

I found this error when consumes bazel-common in our sample-android project

ERROR: PackageAndroidResources failed: not all outputs were created or valid
CONFLICT: string/generated_value is provided with ambiguous priority from: sample-android / flavors/sample-android-flavor

In Android, a resource conflict happens when two modules declare a resource with the same name (common) when using resValue in build.gradle to generate build-type or flavor identifiers). Gradle resolves these silently by priority e.g. app/binary resources win over library resources

Without this fix

  • Building any android_binary target where resource names overlap between modules fails with a hard error (explained above).
  • On top of that, even when conflicts are allowed, there is no guaranteed priority ordering, the wrong
    resource value could silently win.

With this fix

  • Builds succeed when resource names overlap across modules, matching Gradle's permissive behavior.
  • The binary's own resValue-generated resources always take priority over same-named resources from
    library deps, matching Gradle's resolution order.

Root cause

rules_android 0.7.1 introduced a new Starlark-based resource pipeline (busybox.bzl) with an ACL allowlist (allow_resource_conflicts.bzl) that defaults to empty, making all conflicts hard errors. This replaced Bazel 7's native android_binary which defaulted throwOnResourceConflict=false. The previous workaround disable-resource-conflicts.patch inside all_android_tools_deploy.jar suppressing warnings in AndroidDataMerger.java, since the new pipeline no longer invokes AndroidDataMerger.

Changes

  • Patch allow_resource_conflicts.bzl to add //:subpackages to the ACL allowlist, so resource conflicts
    in all workspace modules are treated as warnings instead of errors.
  • Separate res_values-generated resources from regular resource_files in resources.bzl as a distinct
    res_values_resources field.
  • In android_binary.bzl, pass res_values_resources directly to native.android_binary's own resource_files
    (instead of through kt_android_library dep), giving them binary-level priority in conflict resolution.
  • In android_library.bzl, keep res_values_resources merged into resource_files as before (library-level
    priority).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant