HarmonyOS 鸿蒙Next多products配置如何编译release版本

HarmonyOS 鸿蒙Next多products配置如何编译release版本

products里面配置default 和 release, DevEco里面菜单 Build->Build App(s), 编译出来的只有 EnglishBook-default-signed.app 那么,如何编译出release product呢?

{
  "app": {
    "products": [
      {
        "name": "default",
        "signingConfig": "default",
        "compatibleSdkVersion": "5.0.0(12)",
        "runtimeOS": "HarmonyOS"
      },
      {
        "name": "release",
        "signingConfig": "release",
        "compatibleSdkVersion": "5.0.0(12)",
        "runtimeOS": "HarmonyOS"
      }
    ],
    "buildModeSet": [
      {
        "name": "debug"
      },
      {
        "name": "release"
      }
    ],
    "signingConfigs": [
      {
        "name": "default",
        "type": "HarmonyOS",
        "material": {
          ...
        }
      },
      {
        "name": "release",
        "type": "HarmonyOS",
        "material": {
          ...
        }
      }
    ],
    "modules": [
      {
        "name": "entry",
        "srcPath": "./entry",
        "targets": [
          {
            "name": "default",
            "applyToProducts": [
              "default"
            ]
          }
        ]
      }
    ],
  }
}

更多关于HarmonyOS 鸿蒙Next多products配置如何编译release版本的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

需要将 targets 添加进 product 后,切换需要运行的product, 如这边 的 entry 模块

{
      "name": "entry",
      "srcPath": "./entry",
      "targets": [
        {
          "name": "default",
          "applyToProducts": [
             "default","release"
          ]
        }
      ]
    },

配置参考文档: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-customized-multi-targets-and-products-guides-0000001731595144-V5#section7613106105114

切换product、target参考文档: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-customized-multi-targets-and-products-guides-0000001731595144-V5#section2554174114463

更多关于HarmonyOS 鸿蒙Next多products配置如何编译release版本的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS中,编译多products配置的release版本可以通过以下步骤实现:

  1. 配置Product:在products目录下定义你的产品配置文件,例如product.json,指定产品名称、设备类型、模块依赖等信息。

  2. 配置Build Variant:在build目录下的build.profile文件中,配置release构建变体。设置buildTyperelease,并定义相关的编译选项,如优化级别、符号表处理等。

  3. 调用编译命令:在项目根目录下运行编译命令。使用hb build命令时,指定-f参数强制重新编译,并加上--build-type release参数来构建release版本。例如:

    hb build -f --build-type release
    
  4. 签名配置:确保在build目录下的signature配置文件中,配置了release版本的签名信息,包括证书、密钥等。

  5. 输出结果:编译完成后,生成的release版本文件会输出到out目录下的相应产品文件夹中,通常以.bin.img文件形式存在。

通过以上步骤,你可以成功编译HarmonyOS Next多products配置的release版本。

回到顶部