Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resource merging for flavored source sets #89

Merged
merged 3 commits into from
Apr 25, 2023

Conversation

arunkumar9t2
Copy link
Contributor

@arunkumar9t2 arunkumar9t2 commented Apr 24, 2023

This PR introduces new API in the previously introduced unified macro #87 for resource pre-processing.

In AGP land, we can have multiple resource directories for a variant and before calling aapt AGP would merge these sources based on priority order BuildType -> Flavor -> main -> Dependencies. This PR tries to implement the same functionality by introducing a new tool RESOURCE_MERGER and a new android rule API resources to specify multiple source sets. Internally merging is performed using same code from the android_tools package that bazel uses and then the result is passed to resource_files as usual.

The structure lays foundation for worker support, asset and manifest merging support later on.

Implementation notes

  • Backwards compatible with resource_files API
  • Sorting order is used to denote priority of directories
  • tools/aapt_lite/src/main/java/com/google/devtools/build/android/ResourceMerger.java is in Java since android_tools had trouble getting added as Kotlin dependency
  • Each resource directory accepts a dict so as to pass additional information like manifests in the future.
  • Only directories are accepted
  • Expand locations and make variables are not supported yet.

Example usage

android_binary(
    name = "sample-android-flavor1-paid-debug",
    srcs = glob([
        "src/main/java/com/grab/grazel/android/sample/MainActivity.kt",
    ]),
    assets = glob([
        "src/main/assets/assert-file.png",
    ]),
    assets_dir = "src/main/assets",
    custom_package = "com.grab.grazel.android.sample",
    resources = {
        "src/main/res-debug": {},
        "src/paid/res": {},
        "src/main/res": {},
    },
)

@arunkumar9t2 arunkumar9t2 added the enhancement New feature or request label Apr 24, 2023
@arunkumar9t2 arunkumar9t2 self-assigned this Apr 24, 2023
@arunkumar9t2 arunkumar9t2 marked this pull request as ready for review April 25, 2023 06:55
@arunkumar9t2 arunkumar9t2 merged commit fdcec09 into master Apr 25, 2023
@arunkumar9t2 arunkumar9t2 deleted the resource-pre-processor branch April 25, 2023 07:25
akshay-grabtaxi pushed a commit that referenced this pull request Jun 28, 2023
* Implement resource merging for flavored source sets

* Push missed file

* Ensure outputs are present and handle cases like empty resource files
pswaminathan pushed a commit to pswaminathan/grab-bazel-common that referenced this pull request Jul 7, 2023
* Implement resource merging for flavored source sets

* Push missed file

* Ensure outputs are present and handle cases like empty resource files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants