【HarmonyOS NEXT】在DevEco Studio中设置product配置,实际不生效,如何解决

本文介绍了在DevEcoStudio中设置product配置时遇到deviceType不一致问题,提供了解决方案并强调了每个product与deviceType的对应关系。
摘要由CSDN通过智能技术生成

【关键字】

编译构建 / 配置APP多目标构建产物 / deviceType不唯一

【问题描述】

在DevEco Studio中设置product配置,实际不生效,如何解决?

应用的工程为一个Entry模块。

根目录的build-profile配置了default project中支持两个target, 根目录build-profile的配置项如下:

"modules": [
    {
      "name": "entry",
      "srcPath": "./entry",
      "targets": [
        {
          "name": "default",
          "applyToProducts": [
            "default"
          ]
        },
        {
          "name": "free",
          //将free target打包到productA APP中
          "applyToProducts": [
            "default",
          ]
        },
      ]
    }

Entry模块配置下的build-profile

"targets": [
    {
      "name": "default",
      "runtimeOS": "HarmonyOS",
      "output": {
        "artifactName": "defaultTarget"  //产物名称为customizedTargetOutputName
      },
      "config": {
        "deviceType": [  //定义free支持的设备类型为phone
          "tablet"
        ]
      },
      "source": {  //定义Stage模型中默认版target的pages源码文件
        "pages": [
          "pages/Index"
        ]
      }
    },
    {
      "name": "free",  //免费版target名称
      "runtimeOS": "HarmonyOS",
      "output": {
        "artifactName": "freeTarget"  //产物名称为customizedTargetOutputName
      },
      "config": {
        "deviceType": [  //定义free支持的设备类型为phone
          "tablet"
        ]
      },
      "source": {  //定义Stage模型中默认版target的pages源码文件
        "pages": [
          "pages/Index",
          "pages/Page2"
        ]
      }
    },
 ]

在DevEco Studio中点击右上角的cke_3296.png图标,配置了需要打包的product为default,module Target为default,如下图所示。

cke_4810.png

选择Build > Build Hap(s)/APP(s) > Build APP(s),进行编译打包如下图所示。

cke_7196.png

编译报错如下:

2024/01/02 10:03:26.754 - Ohos BundleTool [Error]: Module: (entry) and Module: (entry) have the same moduleName, please check deviceType or distroFilter of the module.
2024/01/02 10:03:26.754 - Ohos BundleTool [Error]: Module: entry has deviceType [tablet].
2024/01/02 10:03:26.754 - Ohos BundleTool [Error]: Another Module: entry has deviceType [tablet].2024/01/02 10:03:26.754 - Ohos BundleTool [Error]: Solution: Make sure the module name is valid and unique.

报错提示,根目录的build-profile文件targets配置中两个target对应的deviceType都是tablet,不唯一。

所以怀疑通过DevEco Studio中点击右上角配置了所选的product为default,module Target为default,实际没生效,导致在选择Build > Build Hap(s)/APP(s) > Build APP(s)进行编译打包时,将free的包错误打包了。

【解决方案】

根据上面配置文件判断只有一个product,即默认的default。在对应的Entry/Feature模块下配置target后,会在编译后生成不同target的HAP。如果此时通过Build App的方式打包,App中会包含不同目标的HAP产物,不同目标的产物会分发到不同的目标设备上。

例如:Entry下free的deviceType为phone,default为tablet,在应用市场分发的时候,手机设备phone只会分发到App中的free对应的HAP包,平板设备tablet只会分发到default对应的HAP包。

如果需要通过Build App的方式打包多目标产物,即构建不同的目标的App文件,需要在项目级build-profile文件中设置不同product,在IDE中选择Product后就只会生成对应目标的App。

具体配置APP多目标构建产物的详细介绍请参见:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-customized-multi-targets-and-products-guides-0000001731595144#section680552311459

每个target对应一个HAP,每个product对应一个APP包,APP包由多个目标的HAP组成,因此在执行Build > Build Hap(s)/APP(s) > Build APP(s)时,会把所有的target都编译打包。因为编译的APP包里只有一个product,这个product包含2个HAP包,所以会把这2个HAP包都编译。

  • 23
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值