How do I restrict Gradle native binary build based on combination of flavour, platform and build type?

When you configure a set of variant dimensions (platforms/buildTypes/flavors) you’re configuring the entire possible set of binary variants that can be built.

There are a couple of ways of restricting the set that will be built:

  • Allow Gradle to choose what should be built by building the top-level executable/libraries required, with Gradle building the required library dependencies.
  • Target a component at a restricted subset of variant dimensions: http ://www.gradle.org/docs/nightly/userguide/nativeBinaries.html#N15EFE
  • Only calling the tasks for the binaries you want to build (or creating a task that depends on these binaries)
  • Setting the ‘buildable’ flag to false for any binary you don’t want built
The third option looks something like this. It’s not pretty but it works:
binaries.all {
    if (platform.operatingSystem.macOsX) {
        if (buildType == buildTypes.release) {
            if (flavor.name != “export”) {
                 buildable = false
            }
        }
    }
} task buildAll {

dependsOn binaries.matching {

it.buildable

} }