Question

Is it possible to config Gradle to build few android apk files where each would be using only one resource-type folder?

I mean:

  • build-hdpi.apk
  • build-mdpi.apk
  • build-xhdpi.apk

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"?

Was it helpful?

Solution

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'
     }
}
  • enable: enables the density split mechanism
  • exclude: By default all densities are included, you can remove some densities.
  • include: indicate which densities to be included
  • reset(): reset the list of densities to be included to an empty string (this allows, in conjunctions with include, to indicate which one to use rather than which ones to ignore)
  • compatibleScreens: indicates a list of compatible screens. This will inject a matching node in the manifest. This is optional.

Example in AOSP: https://android.googlesource.com/platform/tools/base/+/2101d189d85dd46f865726b9b7aa0012832a6d9c/build-system/tests/regular/densitySplit/build.gradle

OTHER TIPS

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"
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top