background

As the project continues to grow, there may be hundreds of files in resource directories such as Layout, which leads to low search efficiency. When multiple people modify key-value files such as strings. XML, conflicts frequently occur.

solution

Res is subcontracted according to business modules like SRC code. Different developers are responsible for maintaining different packages, with clear structure and less conflicts.

Specific operation

  1. Create the res_xxx directory

In the main directory, create directories such as res_core and res_feed (named according to the service module). In the res_core directory, create folders such as Layout, drawable- xxHDpi, and values that are identical to the res directory.

Attention to details: To avoid duplicate resource names, you are advised to prefix the resource file names in different modules with the module name, for example, core_icon_xxx. PNG, core_activity_xxx. In files such as strings.xml, prefix the key of the resource with the module name.

<resources>
    <string name="core_demo">demo</string>
    <string name="core_app_name">demo_0221_res</string>
</resources>
Copy the code
  1. Configure the res_xx directory
android {
    //...
    sourceSets {
        main {
            res.srcDirs(
                    'src/main/res'.'src/main/res_core'.'src/main/res_feed',)}}}Copy the code