简体   繁体   English

Gradle 只构建一种风味

[英]Gradle Build only a flavour

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.当 Dev 是我的不同口味之一。 Indeed, I have to execute:确实,我必须执行:

gradle build

And all flavors are build.并且所有的口味都是建立的。

I'd like to skip some flavors.我想跳过一些口味。 is it possible?是否可以?

Thanks谢谢

While there is no flavor-specific version of the build task, there are flavor-specific versions of the assemble and install tasks.虽然没有特定版本的build任务,但有特定版本的assembleinstall任务。 assemble will create the APK; assemble将创建 APK; install will install it on devices/emulators. install会将其安装在设备/模拟器上。

For example, in this sample project , I define two product flavors ( chocolate and vanilla ) and three total build types ( debug , release , and mezzanine ).例如,在这个示例项目中,我定义了两种产品口味( chocolatevanilla )和三种总构建类型( debugreleasemezzanine )。

Running gradle tasks shows, 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

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

If your productFlavor is chocolate you can do如果您的产品口味是巧克力,您可以这样做

./gradlew assembleChocolateRelease

or或者

./gradlew assembleChocolateDebug

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM