有人能告诉我是否可以通过命令行只构建我的不同风味中的一个吗?
目前我还没有找到例如执行以下命令的方法:
gradle buildDev
当Dev是我不同的味道之一时。实际上,我必须执行:
gradle build
所有口味都已经构建完成。
我想跳过一些口味。这可行吗?
谢谢。
虽然没有特定于口味的build
任务版本,但有特定于口味的assemble
和install
任务版本。assemble
将创建APK;install
将在设备/模拟器上安装它。
例如,在此示例项目中,我定义了两个产品风味(chocolate
和vanilla
)和三种总构建类型(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
gradle assembleChocolateDebug
将会在你的项目中生成一个路径为 build/apk/HelloProductFlavors-chocolate-debug-unaligned.apk
的文件。不过,我不能排除只有在口感可口的情况下才有效的可能性。 :-) - CommonsWare:<module>:assemble<FlavorName>
。 - Torgebuild.gradle
,请查看 https://github.com/commonsguy/cw-omnibus/blob/v9.0/Manifest/Merger/app/build.gradle - CommonsWare我会简化@CommonsWare所提供的答案,因为在阅读该答案时我有点困惑。
考虑这些是产品口味
运行
gradlew task
这将列出所有产品口味以及其构建类型。
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
如果你的产品口味是巧克力,你可以这样做
./gradlew assembleChocolateRelease
或者./gradlew assembleChocolateDebug
补充以上答案,如果要构建 Android Bundle(AAB),则可以使用以下方法
# build flavor 'flavorName' only
./gradlew bundleFlavorName
gradle
而不使用参数,然后读取输出...将会提示运行gradle tasks
... - Selvin