HarmonyOS 粒子特效实战:hvigor 多模块三坑:HAR module.json5 / --modules / oh_modules(HarmonyOS)
hvigor 多模块三坑:HAR module.json5 / --modules / oh_modules(HarmonyOS)
现象: 三模块项目(entry + common HAR + lab HAR)刚脚手架完就三连炸:
00304064 Not Found、lab/oh_modules/进了 git、Multiple entry modules found。
原因: hvigor 6.1.1(DevEco 6.1.1)强制要求每个 HAR 模块有 module.json5;CLI 无法自动区分 HAP/HAR,把三个模块都当 entry 候选;脚手架.gitignore用/oh_modules只锚定根目录。
解决: 每个 HAR 补 module.json5;构建--modules entry(HAR 连带编译);.gitignore改**/oh_modules。
坑1:00304064 Not Found — module.json5 file not found
报错指向 common/src/main/module.json5 缺失。老版 HAR 模板不需要这个文件,但 hvigor 6.1.1 的 sync 阶段强制检查。
解法:每个 HAR 补 src/main/module.json5:
{
"module": {
"name": "common",
"type": "har",
"deviceTypes": ["phone", "tablet"]
}
}
全量编译通过验证。
坑2:子模块 oh_modules 进了 git
本地 HAR 依赖会被 ohpm 复制进子模块的 oh_modules/。脚手架 .gitignore 写的是 /oh_modules,只锚定根目录,lab/oh_modules/ 照样进 git。
解法一处改动:
**/oh_modules
git status 复查干净。
坑3:Multiple entry modules found
CLI 分不清哪个是 HAP 哪个是 HAR,把三个模块都当 entry 候选:
Multiple entry modules found (entry, common, lab)
解法:构建时显式指定 entry 模块,HAR 作为依赖连带编译:
devecocli build --modules entry
附录:编译级小坑速查
| 小坑 | 现象 | 解法 |
|---|---|---|
| Slider 回调类型 | 编译报 Cannot find name 'ChangeMode' | 第二参类型是 SliderChangeMode(slider.d.ts:1559 声明),写 (value: number, mode: SliderChangeMode) => void |
| router 已废弃 | pushUrl has been deprecated 警告 | 统一 this.getUIContext().getRouter().pushUrl(...) |
| Image 位置参数 | 给 Image 传 {src: ...} 报 no overload | Image 构造是位置参数:Image(src) |
标签
#HarmonyOS #hvigor #HAR #module #devecocli #gitignore #ArkTS
📹 效果演示:本合集的粒子消散、马赛克飞散等动态效果实录会发在抖音——号 581821159(天行健之初九),截图看不出的粒子细节,视频一眼就懂。
懿路向前 · AI辅助整理 · 2026-10-12
更多推荐



所有评论(0)