Resource merging during gradle builds with different approaches

As we know there are two ways of having separate res directories for each productFlavor or buildType.

First Approach is by having separate directories under the src folder e.g. src\flavor1\res, src\flavor2\res etc.

Second Approach is specifying the res directory under sourceSets in the build.gradle like

sourceSets {
    main {
        res.srcDirs    = ['res']
    }
    dev {
        res.srcDirs    = ['res-dev']
    }
}

I know for sure that resource merging will happen in the first approach and any missing resource in the separate directory for flavor will be picked up from the main's sourceSet.

Question is about second approach above.

Will resource merging happen in the same way as it happens with the first approach using separate folders? Here i am explicitly going to assign a separate directory. Does it still fallback to main for resources not found in the specified directory?

I ask this because of the example in THIS LINK on http://tools.android.com/ where towards the end of the article it shows 'src/main/res' being explicitly added as follows:

android.sourceSets {
   main.res.srcDirs = ['src/main/res', 'src/main/res2']
}

Has anyone done this and knows if the resource merging will still happen if i just give the additional directory and not main as an additional one? will it fallback to the main directory for missing resources?

Answers


Ok, I tried out for myself with each of the above scenarios. Findings were as follows:

  1. There is no need to specify the src\main\res directory. The fallback happens in both approach to the main res directory.
  2. This worked absolutely well for both res and assets folder. And I assume it will work exactly same for other folders too. I did not need those so havent tried. But, I cant think of any reason why they wont work when res and assets folders do.

Hence, it works as expected.


Need Your Help

Get Directions for multiple locations in GMAP iOS.

ios iphone objective-c google-maps location

I have an array which contains multiple locations (latitude and longitude).