Gradle Build只是一种味道

Jos*_*hon 81 android build gradle

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

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

gradle buildDev 
Run Code Online (Sandbox Code Playgroud)

Dev是我的不同口味之一.的确,我必须执行:

gradle build
Run Code Online (Sandbox Code Playgroud)

所有口味都是建立的.

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

谢谢

Com*_*are 140

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

例如,在此示例项目,我定义了两个产品的口味(chocolatevanilla)和三个总建筑类型(debug,release,和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
Run Code Online (Sandbox Code Playgroud)

  • @Lechon:**`gradle assembleChocolateDebug`**将导致`build/apk/HelloProductFlavors-chocolate-debug-unaligned.apk`被放置在你的项目中.虽然,我不能排除只有味道好吃才有效的可能性.:-) (11认同)
  • 如果你有模块,不要忘记模块前缀`:<module>:assemble <FlavorName>` (3认同)
  • 然后,当我想要构建风味的APK时,我必须使用assembleXXX.凉.谢谢. (2认同)
  • @Zainodis:这个答案已有一年多了,他们可能已经添加了一个任务,可以为所有产品风格组装调试版本类型. (2认同)

dro*_*kid 26

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

考虑这些是产品口味

  • 开发
  • Preprod

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.
Run Code Online (Sandbox Code Playgroud)

从中您可以轻松选择口味并基于此生成构建

gradlew assemblePREPROD


Eri*_*Kim 6

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

./gradlew assembleChocolateRelease
Run Code Online (Sandbox Code Playgroud)

要么

./gradlew assembleChocolateDebug
Run Code Online (Sandbox Code Playgroud)


EFr*_*eak 5

要添加到上面的答案,如果你想构建一个 Android Bundle (AAB) 那么你可以使用这个

# build flavor 'flavorName' only
./gradlew bundleFlavorName
Run Code Online (Sandbox Code Playgroud)