hvigor构建报错

399 阅读1分钟

Sync failed. Follow the given solution to avoid unexpected errors. Cause: The @ohos/hvigor-ohos-plugin version (3.0.9) is not within the expected range 2.x.x (2.x.x >= 2.4.0). Solution: 1.Switch to @ohos/hvigor-ohos-plugin 2.4.2(which will install @ohos/hvigor 2.4.2) and import the project again. 2.Alternatively, update DevEco Studio and import the project again.

image.png

当引入其他人写的项目时候, 就容易报这个错, 并且 "ide" 已经是最新版本

image.png

改好需要3步

step1. 全局搜索 @ohos/hvigor-ohos-plugin

image.png

step1.1 修改 hvigor/hvigor-config.json5

修改之前

{
  "hvigorVersion": "3.0.9",
  "dependencies": {
    "@ohos/hvigor-ohos-plugin": "3.0.9"
  },
  "execution": {
    // "daemon": true,                          /* Enable daemon compilation. Default: true */
    // "incremental": true,                     /* Enable incremental compilation. Default: true */
    // "parallel": true,                        /* Enable parallel compilation. Default: true */
    // "typeCheck": false,                      /* Enable typeCheck. Default: false */
  },
  "logging": {
    // "level": "info"                          /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
  },
  "debugging": {
    // "stacktrace": false                      /* Disable stacktrace compilation. Default: false */
  }
}

修改之后,把 hvigor 版本从 3.0.9 改成 2.4.2

{
  "hvigorVersion": "2.4.2",
  "dependencies": {
    "@ohos/hvigor-ohos-plugin": "2.4.2"
  },
  "execution": {
    // "daemon": true,                          /* Enable daemon compilation. Default: true */
    // "incremental": true,                     /* Enable incremental compilation. Default: true */
    // "parallel": true,                        /* Enable parallel compilation. Default: true */
    // "typeCheck": false,                      /* Enable typeCheck. Default: false */
  },
  "logging": {
    // "level": "info"                          /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
  },
  "debugging": {
    // "stacktrace": false                      /* Disable stacktrace compilation. Default: false */
  }
}

step2 修改 hvigorfile.ts

修改之前

import { hapTasks } from '@ohos/hvigor-ohos-plugin';

export default {
    system: hapTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */
    plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */
}

修改之后

// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { appTasks } from '@ohos/hvigor-ohos-plugin';

step3 修改 你的项目/entry/hvigorfile.ts

修改之前

import { hapTasks } from '@ohos/hvigor-ohos-plugin';

export default {
    system: hapTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */
    plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */
}

修改之后

// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { hapTasks } from '@ohos/hvigor-ohos-plugin';

step4 继续~~

如果前三步发现,如下错误

image.png

修改 build-profile.json5, 删除 buildModeSet 对象

image.png

image.png

OK~~, 谢谢大家观看~~~