Reputation: 2866
Is it possible to config Gradle to build few android apk files where each would be using only one resource-type folder?
I mean:
I know I could simply remove certain folders before building, but it would be nice if I could make it "automagically".
Would it be possible with using gradle "flavors"?
Upvotes: 11
Views: 2075
Reputation: 7727
Now we can also use api splits http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
Example From the docs link :
android {
...
splits {
density {
enable true
exclude "ldpi", "tvdpi", "xxxhdpi"
compatibleScreens 'small', 'normal', 'large', 'xlarge'
}
}
Example in AOSP: https://android.googlesource.com/platform/tools/base/+/2101d189d85dd46f865726b9b7aa0012832a6d9c/build-system/tests/regular/densitySplit/build.gradle
Upvotes: 9
Reputation: 28529
Its not yet possible, but 0.7.0 will have this feature.
You'll need to create 3 product flavors (or more if you want to support all densities), and you'll have a flavor property to restrict what to package in the apk.
0.7.0 will be out shortly.
Note that the Multi APK support in the Play Store does not support density as a filter, that would show up as 3 different apps on the store which is not what you'd want. Edit: this is actually supported by Multiple Apks: http://developer.android.com/google/play/publishing/multiple-apks.html
Edit2: Now that 0.7.+ is out, you can do the following:
android {
productFlavors {
mdpi {
resConfigs "mdpi", "nodpi"
}
hdpi {
resConfigs "hdpi", "nodpi"
}
xhdpi {
resConfigs "xhdpi", "nodpi"
}
}
}
Upvotes: 8