I am new to gradle and want to use the gradle android plugin with flavors, buildtypes and custom sourcesets. Building with flavors and buildtypes works find. Unfortunately I have a legacy project directory structure, so I have to customize the res directory for the buildtypes.
Somehow the additional resources (basically some string config values) for a buildtype do not seem to get merged into the build and do not replace resource keys from the main tree.
This was asked before, I know there is Gradle productflavors sourcesets and old project structure and How can I specify per flavor buildType sourceSets?
I want to quote Xavier from the first post: "You need to first declare your flavors and then customize the sourceSets."
I understand that a flavor configuration automatically creates sourcesets and that they need to be modified afterwards. Thats what I tried in the following build.gradle, but my added "res.srcDirs" for each buildtype seem to get ignored and I cannot figure out why.
In the second post (last comment with the link to github), I see complicated sourceset modification in the build.gradle. Is there also a simpler way for this? (see here: https://github.com/shakalaca/learning_gradle_android/blob/master/07_tricks/app/build.gradle)
This is my build configuration for the gradle android plugin:
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
productFlavors {
normal {
}
proguard {
proguardFile file("proguard-project.txt")
}
}
buildTypes {
dev {
packageNameSuffix ".dev"
debuggable true
signingConfig android.signingConfigs.debug
}
beta {
packageNameSuffix ".beta"
debuggable true
signingConfig android.signingConfigs.debug
}
live {
packageNameSuffix ".live"
debuggable true
signingConfig android.signingConfigs.debug
}
}
sourceSets.dev.res.srcDirs = ['variations/dev']
sourceSets.beta.res.srcDirs = ['variations/staging']
sourceSets.live.res.srcDirs = ['variations/live']
}