How does one exclude flavors not applicable for certain platforms?


(michael.nikonov) #1

Good afternoon!

I’ve ran into a specific task, and want to ask if someone knows how to solve it. I have a native project that targets several embedded bare-metal platforms that share same code base. The ‘build.gradle’ defines this kind of model:

model {
  // ...
    platforms {
    create("hwRev1A")
    create("hwRev1B")
  }
    flavors {
    create("basic")
    create("featureSetA")
    create("featureSetB")
  }
}

with ‘hwRev1A’ and ‘hwRev1B’ are different hardware revisions of target platform, and flavors tailoring the set of enabled functions for specific usage scenario. At that, revision 1A only supports basic flavor because of hardware limitations, and there’s no point building all flavors for it. I wonder if there’s a way to specify that only certain flavors should be built for given platform?


#2

Currently, Gradle will create a ‘NativeBinary’ model object for all combinations of flavors & platforms that are defined for a component (library or executable). You decide which of these to actually build. 

Gradle does provide some assistance: the ‘buildable’ flag. So ‘NativeBinary.buildable’ is only true when there is a toolchain available that can target the specified platform. You can then write a task that will build all ‘buildable’ native binary instances. (See the “tool-chains” sample under ‘subprojects/docs/src/samples/native-binaries’ for an example.

So you could extend this by setting ‘buildable = false’ for any platform/flavor combinations that don’t make sense, and then use this flag to determine what to build. Eventually the Gradle lifecycle tasks will probably use this flag automatically.


(michael.nikonov) #3

Thank you! It was the build task from the example that I was using, one that was building everything with buildable flag set. It didn’t happen to me that I could reset the flag for certain combinations; I tried, and it works fine, just how I needed it to.