Is there a way to have compile dependencies by multiple flavors in Android Studio (build.gradle)?
I have 2 flavorGroups, and in each 2 variants. Out of the 4 possible combinations I would like to be able to depend on a lib only if I'm both in latest and in free flavor. latestCompile or freeCompile works, but latestFreeCompile doesn't. this is the relevant part of my build.gradle:
android {
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 15
versionName "1.9." + versionCode
}
flavorGroups 'sdk', 'cost'
productFlavors {
latest {
flavorGroup 'sdk'
minSdkVersion 8
}
sdk7 {
flavorGroup 'sdk'
minSdkVersion 7
versionName android.defaultConfig.versionName + ".sdk7"
}
free {
flavorGroup 'cost'
}
pro {
flavorGroup 'cost'
}
}
}
dependencies {
// this works:
freeCompile files('libs/StartAppInApp-2.2.1.jar')
// and I would like something like this:
latestFreeCompile 'com.google.android.gms:play-services:4.1.32' // minSdkVersion:8
}
If I would use:
latestCompile 'com.google.android.gms:play-services:4.1.32'
then it would be included in latestPro as well (not needed) and if I'd use:
freeCompile 'com.google.android.gms:play-services:4.1.32'
then it would be included in sdk7Free as well (although it needs SDK 8)
Same issue here, but Pawel's solution didn't work because gradle dependencies have other issues in which it starts building not only the selected flavors/build type, but all of them and it requires a more dynamic solution.
Still I found this issue tracker: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=52962
There is also a reference to fixing the rebuild-all bug I mentioned above, but I didn't try it yet.
And implemented this solution (as per issue tracker reply #60):
I had the same problem. I resolved that with some gradle code in my build.gradle:
Then all you need is to add following code inside your 'dependencies' section: