How can I specify per flavor buildType sourceSets?

android, gradle

Solution

For Google Maps API integration you can check my gradle sample code here : https://github.com/shakalaca/learning_gradle_android/tree/master/07_tricks

Basically do a little trick in `android.applicationVariants.all` during the `mergeResources` phase, and place the API key in strings.xml under different flaver/buildtype combination folder.

Problem

I've got 2 flavors of an app that each have their own google maps (v1) key for debug and release (meaning 4 keys total). So I'd like to know if I can specify sourceSets based on the buildType and productFlavor. Essentially, I'm wondering how I can achieve something like this: ``` src ├── debug │   └── flavor1 │   └── res │ └── values │ └── gmaps_key.xml ├── release │ └──flavor1 │ └── res │ └── values │ └── gmaps_key.xml ``` Where gradle will use the `src/<currentBuldType>/<currentProductFlavor>/*` as part of its sourceSet. Essentially I want it so that if I run `gradle assembleFlavor1Debug` it will include everything under `src/main/*`, `src/flavor1/*`, and `src/debug/flavor1/*`. My build.gradle is super simple: ``` buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.0' } } apply plugin: 'android' android { compileSdkVersion 8 productFlavors { flavor1 { packageName 'com.flavor1' } flavor2 { packageName 'com.flavor2' } } } ``` Any thoughts? Or maybe a better approach to this?

Original source