Gradle: How to Build different flavours of different built types?

AndroidBuildGradle

Android Problem Overview


Could someone tell me if it's possible to build only one of my different flavors through the command-line?

At the moment I haven't seen the way to execute, for example:

gradle buildDev 

when Dev is one of my different flavors. Indeed, I have to execute:

gradle build

And all flavors are build.

I'd like to skip some flavors. is it possible?

Thanks

Android Solutions


Solution 1 - Android

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 Chocolate
assembleChocolateDebug - Assembles the Debug build for flavor Chocolate
assembleChocolateDebugTest - Assembles the Test build for the ChocolateDebug build
assembleChocolateMezzanine - Assembles the Mezzanine build for flavor Chocolate
assembleChocolateRelease - Assembles the Release build for flavor Chocolate
assembleDebug - Assembles all Debug builds
assembleMezzanine - Assembles all Mezzanine builds
assembleRelease - Assembles all Release builds
assembleTest - Assembles all the Test applications
assembleVanilla - Assembles all builds for flavor Vanilla
assembleVanillaDebug - Assembles the Debug build for flavor Vanilla
assembleVanillaDebugTest - Assembles the Test build for the VanillaDebug build
assembleVanillaMezzanine - Assembles the Mezzanine build for flavor Vanilla
assembleVanillaRelease - Assembles the Release build for flavor Vanilla

Install tasks
-------------
installChocolateDebug - Installs the Debug build for flavor Chocolate
installChocolateDebugTest - Installs the Test build for the ChocolateDebug build
installChocolateMezzanine - Installs the Mezzanine build for flavor Chocolate
installChocolateRelease - Installs the Release build for flavor Chocolate
installVanillaDebug - Installs the Debug build for flavor Vanilla
installVanillaDebugTest - Installs the Test build for the VanillaDebug build
installVanillaMezzanine - Installs the Mezzanine build for flavor Vanilla
installVanillaRelease - Installs the Release build for flavor Vanilla
uninstallAll - Uninstall all applications.
uninstallChocolateDebug - Uninstalls the Debug build for flavor Chocolate
uninstallChocolateDebugTest - Uninstalls the Test build for the ChocolateDebug build
uninstallChocolateMezzanine - Uninstalls the Mezzanine build for flavor Chocolate
uninstallChocolateRelease - Uninstalls the Release build for flavor Chocolate
uninstallVanillaDebug - Uninstalls the Debug build for flavor Vanilla
uninstallVanillaDebugTest - Uninstalls the Test build for the VanillaDebug build
uninstallVanillaMezzanine - Uninstalls the Mezzanine build for flavor Vanilla
uninstallVanillaRelease - Uninstalls the Release build for flavor Vanilla

Solution 2 - Android

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

Solution 3 - Android

If your productFlavor is chocolate you can do

./gradlew assembleChocolateRelease

or

./gradlew assembleChocolateDebug

Solution 4 - Android

To add to the above answers, if you want to build an Android Bundle (AAB) then you can use this

# build flavor 'flavorName' only
./gradlew bundleFlavorName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJose M LechonView Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - Androiddroid kidView Answer on Stackoverflow
Solution 3 - AndroidEric KimView Answer on Stackoverflow
Solution 4 - AndroidEFreakView Answer on Stackoverflow