uni-app 运行鸿蒙的时候报错 Invalid product for target 'default'

发布于 1周前 作者 caililin 来自 Uni-App

uni-app 运行鸿蒙的时候报错 Invalid product for target ‘default’

详细报错信息如下
hvigor ERROR: Invalid product for target ‘default’.
Detail: Check the target applyToProducts field for ‘default’: [ ‘default’, ‘release’ ].
at /Users/admin/Desktop/ouyeel_worksheet/unpackage/debug/app-harmony-2f573459/build-profile.json5

hvigor ERROR: BUILD FAILED in 2 s 482 ms
14:58:13.789 运行包制作失败

谁知道这个是怎么回事啊 求教 网上也百度不到类似的答案


更多关于uni-app 运行鸿蒙的时候报错 Invalid product for target 'default'的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

8 回复

贴一下你的build-profile.json5 看看

更多关于uni-app 运行鸿蒙的时候报错 Invalid product for target 'default'的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


{ “app”: { “signingConfigs”: [ { “name”: “default”, “type”: “HarmonyOS”, “material”: { “certpath”: “/Users/admin/.ohos/config/default_MyApplication_ES9EnAkpMlpof9vvrG4Sbz9nkJ95grdGzHr3auEH9jQ=.cer”, “storePassword”: “0000001AD7D2B8B83D40135883AFFB1E40CD211D02BD51AD1AB75CF209EEB4BD90E85307ED1FE934D5AB”, “keyAlias”: “debugKey”, “keyPassword”: “0000001AC132B240A3AE0835EBD738945A5C03B7AD2BEEA2B59036B59E7FF1655A2E501F871C5E3F209F”, “profile”: “/Users/admin/.ohos/config/default_MyApplication_ES9EnAkpMlpof9vvrG4Sbz9nkJ95grdGzHr3auEH9jQ=.p7b”, “signAlg”: “SHA256withECDSA”, “storeFile”: “/Users/admin/.ohos/config/default_MyApplication_ES9EnAkpMlpof9vvrG4Sbz9nkJ95grdGzHr3auEH9jQ=.p12” } } ], “products”: [ { “name”: “default”, “signingConfig”: “default”, “compatibleSdkVersion”: “5.0.0(12)”, “runtimeOS”: “HarmonyOS”, “buildOption”: { “strictMode”: { “caseSensitiveCheck”: true, “useNormalizedOHMUrl”: true } } } ], “buildModeSet”: [ { “name”: “debug” }, { “name”: “release” } ] }, “modules”: [ { “name”: “entry”, “srcPath”: “./entry”, “targets”: [ { “name”: “default”, “applyToProducts”: [ “default”, “release” ] } ] } ] }这样子的

回复 1***@qq.com: 看着好像你的 products 缺了一部分,你补上试试; “products”: [ { “name”: “default”, “signingConfig”: “default”, “compatibleSdkVersion”: “5.0.0(12)”, “runtimeOS”: “HarmonyOS”, “buildOption”: { “strictMode”: { “caseSensitiveCheck”: true, “useNormalizedOHMUrl”: true } } }, { “name”: “release”, “signingConfig”: “release”, “compatibleSdkVersion”: “5.0.0(12)”, “runtimeOS”: “HarmonyOS”, “buildOption”: { “strictMode”: { “caseSensitiveCheck”: true, “useNormalizedOHMUrl”: true } } } ],

回复 DCloud_UNI_yuhe: 赞,解决了我的困惑,为什么鸿蒙开发工具 DevEco Studio 生成自动签名没有 release选项

{ “app”: { “signingConfigs”: [ { “name”: “default”, “type”: “HarmonyOS”, “material”: { “storePassword”: “00000020EB2B14E7B9879477A23F0B0A3210DC192A04785B9347AACE0B8D631AFA1848AF1EACA92D5AD69EE97AA98B88”, “certpath”: “E:/HBuilderProject/certification/Debug_cert.cer”, “keyAlias”: “Debug_alias”, “keyPassword”: “00000020D91D82155E3F142504C29FD7C7678F0D35327C1E8C3A8735C23F3681CA9C0A5460A546BEA21C65135E2DC409”, “profile”: “E:/HBuilderProject/certification/Debug_profileDebug.p7b”, “signAlg”: “SHA256withECDSA”, “storeFile”: “E:/HBuilderProject/certification/Debug_p12.p12” } } ], “products”: [ { “name”: “default”, “signingConfig”: “default”, “compatibleSdkVersion”: “5.0.1(13)”, “runtimeOS”: “HarmonyOS”, “buildOption”: { “strictMode”: { “caseSensitiveCheck”: true, “useNormalizedOHMUrl”: true } } } ], “buildModeSet”: [ { “name”: “debug”, }, { “name”: “release” } ] }, “modules”: [ { “name”: “entry”, “srcPath”: “./entry”, “targets”: [ { “name”: “default”, “applyToProducts”: [ “default” ] } ] } ] } 我这个也报这种错是为啥呢?applyToProducts中也没有release啊

回复 3***@qq.com: 是 products

补上这个relese的配置就可以了,复制下来改个名字

在解决uni-app在鸿蒙系统(HarmonyOS)上运行时出现的“Invalid product for target ‘default’”错误时,通常这是因为项目的配置文件中没有正确设置或指定针对HarmonyOS的编译目标。为了解决这个问题,你需要确保uni-app项目的配置文件(如manifest.jsonvue.config.js等)中包含了针对HarmonyOS的适当配置。

以下是一个基于uni-app项目配置的示例,展示了如何设置以支持HarmonyOS平台:

  1. 修改manifest.json

    manifest.json文件中,你需要确保在mp-weixinh5app-plus等配置之外,还添加了app-harmony的配置。这里是一个简化的例子:

    {
      "mp-weixin": {
        // 微信小程序配置
      },
      "app-plus": {
        // HBuilderX App平台配置
      },
      "app-harmony": { // HarmonyOS平台配置
        "appid": "__UNI__XXXXXX", // 替换为你的HarmonyOS应用ID
        "distribute": {
          "sdkConfigs": []
        }
      },
      // 其他平台配置...
    }
    
  2. 确保vue.config.js(或webpack.config.js)配置正确

    如果你使用自定义的构建配置,确保在构建脚本中正确处理HarmonyOS平台。这可能涉及到条件编译或特定的插件配置。以下是一个假设性的配置示例,用于处理不同平台的构建:

    const isHarmony = process.env.PLATFORM === 'app-harmony';
    
    module.exports = {
      configureWebpack: config => {
        if (isHarmony) {
          // HarmonyOS特定的配置
          config.resolve.alias = {
            '@harmony-components': path.resolve(__dirname, 'src/components/harmony')
          };
        } else {
          // 其他平台的配置
        }
      }
    };
    
  3. 检查环境变量和脚本

    确保你的package.json中的脚本和任何使用的环境变量都正确设置了HarmonyOS的编译目标。例如,你可能需要添加一个脚本来专门编译HarmonyOS版本:

    "scripts": {
      "build:harmony": "cross-env PLATFORM=app-harmony uni-app-cli build"
    }
    
  4. 重新编译项目

    在修改了配置文件后,重新编译你的uni-app项目,确保所有配置都正确加载并生效。

通过上述步骤,你应该能够解决“Invalid product for target ‘default’”的错误,并成功地在HarmonyOS上运行你的uni-app应用。如果问题仍然存在,建议检查uni-app和HarmonyOS SDK的官方文档,以确保所有步骤和配置都是最新的。

回到顶部