Gradle Build only a flavour Gradle Build only a flavour android android

Gradle Build only a flavour


While there is no flavor-specific version of the build task, there are flavor-specific versions of the assemble and install tasks. assemble will create the APK; install will install it on devices/emulators.

For example, in this sample project, I define two product flavors (chocolate and vanilla) and three total build types (debug, release, and mezzanine).

Running gradle tasks shows, among others:

Build tasks-----------assemble - Assembles all variants of all applications and secondary packages.assembleChocolate - Assembles all builds for flavor ChocolateassembleChocolateDebug - Assembles the Debug build for flavor ChocolateassembleChocolateDebugTest - Assembles the Test build for the ChocolateDebug buildassembleChocolateMezzanine - Assembles the Mezzanine build for flavor ChocolateassembleChocolateRelease - Assembles the Release build for flavor ChocolateassembleDebug - Assembles all Debug buildsassembleMezzanine - Assembles all Mezzanine buildsassembleRelease - Assembles all Release buildsassembleTest - Assembles all the Test applicationsassembleVanilla - Assembles all builds for flavor VanillaassembleVanillaDebug - Assembles the Debug build for flavor VanillaassembleVanillaDebugTest - Assembles the Test build for the VanillaDebug buildassembleVanillaMezzanine - Assembles the Mezzanine build for flavor VanillaassembleVanillaRelease - Assembles the Release build for flavor VanillaInstall tasks-------------installChocolateDebug - Installs the Debug build for flavor ChocolateinstallChocolateDebugTest - Installs the Test build for the ChocolateDebug buildinstallChocolateMezzanine - Installs the Mezzanine build for flavor ChocolateinstallChocolateRelease - Installs the Release build for flavor ChocolateinstallVanillaDebug - Installs the Debug build for flavor VanillainstallVanillaDebugTest - Installs the Test build for the VanillaDebug buildinstallVanillaMezzanine - Installs the Mezzanine build for flavor VanillainstallVanillaRelease - Installs the Release build for flavor VanillauninstallAll - Uninstall all applications.uninstallChocolateDebug - Uninstalls the Debug build for flavor ChocolateuninstallChocolateDebugTest - Uninstalls the Test build for the ChocolateDebug builduninstallChocolateMezzanine - Uninstalls the Mezzanine build for flavor ChocolateuninstallChocolateRelease - Uninstalls the Release build for flavor ChocolateuninstallVanillaDebug - Uninstalls the Debug build for flavor VanillauninstallVanillaDebugTest - Uninstalls the Test build for the VanillaDebug builduninstallVanillaMezzanine - Uninstalls the Mezzanine build for flavor VanillauninstallVanillaRelease - Uninstalls the Release build for flavor Vanilla


I would simplify the answer given by @CommonsWare because going through the answer i was litte confused.

Consider these are the product flavours

  • Dev
  • Preprod
  • Prod

Run

gradlew task

This will list out all Product flavours along with there build types

assemble - Assembles all variants of all applications and secondary packages.assembleAndroidTest - Assembles all the Test applications.assembleDebug - Assembles all Debug builds.assembleDEV - Assembles all DEV builds.assemblePREPROD - Assembles all PREPROD builds.assemblePROD - Assembles all PROD builds.assembleRelease - Assembles all Release builds.

From this you can easily choose the flavours and will generate a build based on that

gradlew assemblePREPROD


If your productFlavor is chocolate you can do

./gradlew assembleChocolateRelease

or

./gradlew assembleChocolateDebug