Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle builds for every resource folder

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

like image 641
scana Avatar asked Dec 15 '13 21:12

scana


People also ask

What is the Resources folder in Gradle project?

The resource directory is used mainly for storing files that were created before runtime, so that they can be accessed during runtime. It is not meant to be written to during runtime. So that's why when you set the resource path in Gradle it is not going to set your current working directory to the resource path.

Are Gradle dependencies stored in builds?

The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well.

How many build Gradle files are there?

Why are there two build. gradle files in an Android Studio project?


2 Answers

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

like image 110
Gaurav Vashisth Avatar answered Oct 04 '22 23:10

Gaurav Vashisth


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"
    }
  }
}
like image 36
Xavier Ducrohet Avatar answered Oct 05 '22 01:10

Xavier Ducrohet