摇篮只营造一种味道


92

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

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

gradle buildDev 

开发人员是我的不同口味之一。确实,我必须执行:

gradle build

并且所有口味都在构建。

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

谢谢


首先尝试在gradle没有参数的情况下运行,然后读取输出...会有运行提示gradle tasks...
Selvin 2014年

Answers:


156

虽然没有build任务的特定于版本的版本,但是assembleand install任务具有特定于版本的版本。assemble将创建APK;install将其安装在设备/仿真器上。

例如,在此示例项目,我定义了两个产品的口味(chocolatevanilla)和三个总建筑类型(debugrelease,和mezzanine)。

运行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

2
然后,当我要构建风味的APK时,必须使用assembleXXX。凉。谢谢。
Jose M Lechon 2014年

11
@Lechon:gradle assembleChocolateDebugbuild/apk/HelloProductFlavors-chocolate-debug-unaligned.apk被放置在您的项目中。虽然,我不能排除仅在味道鲜美的情况下才起作用的可能性。:-)
CommonsWare,2014年

2
@Zainodis:这个答案已经使用了一年多了,很可能他们添加了一个任务,该任务将为所有产品口味组装调试构建类型。
CommonsWare,2015年

1
@Zainodis:既然Android 1.0的Gradle已经发布,它应该会放慢一些速度。
CommonsWare 2015年

3
如果您有模块,请不要忘记模块前缀:<module>:assemble<FlavorName>
Torge

28

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

考虑这些是产品口味

  • 开发人员
  • 预生产
  • 产品

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


10

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

./gradlew assembleChocolateRelease

要么

./gradlew assembleChocolateDebug

1

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

# build flavor 'flavorName' only
./gradlew bundleFlavorName
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.