'Resources merging priority on android gradle builds

We want to split our code base into several android library modules. One of them contains common-shared resources (strings, drawables, etc).

The problem arises when one of those resources, let's say app_name, is also defined in another external library. In that case, when all modules are merged, the resource with the id app_name is selected from an external library (randomly?), discarding the resource defined in our own local library module.

Is there a way to set a priority when merging resources to favour an specific library, or at least a module defined locally?



Solution 1:[1]

Update 2022;

Local libraries should already have priority over third-party ones, but to prioritize a local-library over another local-library, simply change your include order.

Open your settings.gradle file, and ensure to include by order of what you want to have priority over others, like:

include ':app' // Heighest priority.
include ':my-library'
include ':my-other-lib' // Lowest priority.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Top-Master