Run a task only if building a specific product flavor?


(misterbushido00) #1

I am migrating my Android project to build with Gradle. I have defined 2 product flavors (“arm7” and “x86”) in my “gradle.build”. These flavors use a different set of library files, which are produced in 2 tasks like so:

tasks.withType(Compile) {
    compileTask -> compileTask.dependsOn(nativeArmLibsToJar, nativeX86LibsToJar);
}

However, I don’t always want to run both tasks. How can I tell Gradle this information, based on the run command? e.g. “gradle assembleArm7” should only run the first task, and “gradle assembleX86” should only run the second task. (And “gradle assemble” should run both.)


(Luke Daley) #2

You should use file based dependencies:

dependencies {
  arm7Compile nativeArmLibsToJar.outputs.files
  x86Compile nativeX86LibsToJar.outputs.files
}