Gradle Build只是一种味道

时间:2014-01-23 11:55:35

标签: android build gradle

有人能告诉我是否可以通过命令行只构建我的一种不同口味?

目前我还没有看到执行方式,例如:

gradle buildDev 
当开发是我不同的口味之一时。的确,我必须执行:

gradle build

所有口味都是建立的。

我想跳过一些口味。 有可能吗?

由于

4 个答案:

答案 0 :(得分:130)

虽然build任务没有特定于风格的版本,但assembleinstall任务的风格特定版本。 assemble将创建APK; install会将其安装在设备/模拟器上。

例如,在this sample project中,我定义了两种产品风格(chocolatevanilla)和三种总体构建类型(debugreleasemezzanine)。

正在运行 gradle tasks ,其中包括:

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

答案 1 :(得分:25)

我会简化@CommonsWare给出的答案,因为通过答案我很困惑。

考虑这些是产品口味

  • Dev
  • Preprod
  • PROD

运行

  

gradlew任务

这将列出所有产品风味以及构建类型

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.

通过这种方式,您可以轻松选择口味,并根据

生成构建
  

gradlew assemblePREPROD

答案 2 :(得分:4)

如果您的品味是巧克力,则可以

./gradlew assembleChocolateRelease

./gradlew assembleChocolateDebug

答案 3 :(得分:0)

要添加到上述答案中,如果您要构建Android捆绑包(AAB),则可以使用此

# build flavor 'flavorName' only
./gradlew bundleFlavorName