If you don't know what this feature does, it allows you to specify an additional directory for the android aapt tool to use when generating the resource files for the apk. From what I can tell the values found in that directory overwrite the ones found in your original res directory.
Since gradle is based on the Groovy language I knew there was a simple way to do this, and here it is in build.gradle:
androidProcessResources.doFirst {
androidConvention.resDirs = files("${projectDir}/res-overlay") + androidConvention.resDirs
}
I found through trial and error that the res-overlay directory needs to be specified first. This was as easy as looking at the source code for the gradle android plugin and seeing where it grabbed the arguments for aapt -S directories and appending them using gradle's doFirst hooks for existing tasks.
One problem I'm still facing is how to add the --auto-add-overlay flag to aapt since the plugin doesn't offer any sort of extraArgs parameter. For now I have a wrapper to aapt that adds that flag to the end of the command. A workaround for sure. I'll update this post when I figure out the answer.
Update
Turns out I don't need that --auto-add-overlay flag after all! I just didn't test the fix without the wrapper.
Update
Turns out I don't need that --auto-add-overlay flag after all! I just didn't test the fix without the wrapper.