【问题标题】:Gradle: How to Build different flavours of different built types?Gradle:如何构建不同构建类型的不同风格?
【发布时间】:2014-02-13 22:59:32
【问题描述】:

谁能告诉我是否可以通过命令行仅构建我的不同风格中的一种?

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

gradle buildDev 

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

gradle build

所有的味道都是建立起来的。

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

谢谢

【问题讨论】:

  • 先尝试不带参数运行gradle,然后读取输出...会有提示运行gradle tasks...

标签: android build gradle


【解决方案1】:

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

例如,在 this sample project 中,我定义了两种产品风格(chocolatevanilla)和三种总构建类型(debugreleasemezzanine)。

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

【讨论】:

  • 然后,当我想构建风味的 APK 时,我必须使用 assembleXXX。凉爽的。谢谢。
  • @Lechon: gradle assembleChocolateDebug 将导致build/apk/HelloProductFlavors-chocolate-debug-unaligned.apk 被放置在您的项目中。不过,我不能排除这种可能性只有在味道鲜美的情况下才有效。 :-)
  • @Zainodis:这个答案已经有一年多了,他们可能已经添加了一个任务,为所有产品风格组装调试构建类型。
  • @Zainodis:现在 Gradle for Android 1.0 已经发布,它应该会放慢一些速度。
  • 如果你有模块,别忘了模块前缀:<module>:assemble<FlavorName>
【解决方案2】:

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

考虑一下这些是产品口味

  • 开发
  • 预制品
  • 产品

运行

毕业任务

这将列出所有产品风格以及构建类型

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

【讨论】:

    【解决方案3】:

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

    ./gradlew assembleChocolateRelease
    

    ./gradlew assembleChocolateDebug
    

    【讨论】:

      【解决方案4】:

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

      # build flavor 'flavorName' only
      ./gradlew bundleFlavorName
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-03
        • 2022-01-23
        • 2021-11-16
        • 1970-01-01
        • 2015-07-21
        • 2015-09-26
        • 1970-01-01
        • 2022-08-09
        相关资源
        最近更新 更多