Android Gradle 只构建一种风味

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21307444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:19:57  来源:igfitidea点击:

Gradle Build only a flavour

androidbuildgradle

提问by Jose M Lechon

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:

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

gradle build

And all flavors are build.

并且所有的口味都是建立的。

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

我想跳过一些口味。是否可以?

Thanks

谢谢

回答by CommonsWare

While there is no flavor-specific version of the buildtask, there are flavor-specific versions of the assembleand installtasks. assemblewill create the APK; installwill install it on devices/emulators.

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

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

例如,在这个示例项目中,我定义了两种产品风格 ( chocolateand vanilla) 和三种总构建类型 ( debugrelease、 和mezzanine)。

Running gradle tasksshows, among others:

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

回答by droid kid

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

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

Consider these are the product flavours

考虑这些是产品口味

  • Dev
  • Preprod
  • Prod
  • 开发
  • 预产
  • 产品

Run

gradlew task

gradlew 任务

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

gradlew 组装PREPROD

回答by Eric Kim

If your productFlavor is chocolate you can do

如果您的产品口味是巧克力,您可以这样做

./gradlew assembleChocolateRelease

or

或者

./gradlew assembleChocolateDebug

回答by EFreak

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

要添加到上述答案,如果您想构建一个 Android Bundle (AAB),那么您可以使用它

# build flavor 'flavorName' only
./gradlew bundleFlavorName