HarmonyOS鸿蒙Next中HNP打包问题
HarmonyOS鸿蒙Next中HNP打包问题 我最近需要把Codex等AI操作机器人把他打包成Hnp 因为它在鸿蒙里面是被支持的 但是呢需要打包为Hnp才可以用 我打包了之后 装到我的环境之后 显示
07:09:17.619: Build task in 37 s 349 ms
07:09:17.621: Launching com.codex.hmos
07:09:17.625: $ hdc shell aa force-stop com.codex.hmos
07:09:18.018: $ hdc shell mkdir data/local/tmp/98e16e64c956452697690c35edfd5c95
07:09:18.161: $ hdc file send C:\Users\Administrator\DevEcoStudioProjects\Codex\entry\build\default\outputs\default\entry-default-signed.hap "data/local/tmp/98e16e64c956452697690c35edfd5c95" in 142 ms
07:09:18.697: $ hdc shell bm install -p data/local/tmp/98e16e64c956452697690c35edfd5c95 in 534 ms
Install Failed: error: failed to install bundle.
code:9568409
error: Failed to install the HAP because the extract of the native package failed.
Search with HarmonyOS Developer
07:09:18.808: $ hdc shell rm -rf data/local/tmp/98e16e64c956452697690c35edfd5c95
07:09:18.812: Launch com.codex.hmos failed, starting handle failure progress
Error while Deploy Hap
我已经确认
- 我的Hnp里面的目录确实是
Hnp-files
|sysroot
|bin
|codex #这是一个ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped可执行文件
|hnp.json #配置文件
- Hnp.json文件里面就是
{
"type": "hnp-config",
"name": "codex",
"version": "1.0",
"install": {}
}
- 以及 我已经在Module文件里面写好了
"hnpPackages": [
{
"package": "codex.hnp",
"type": "public"
}
]
作为放在公开的可执行程序 用来在终端App里面执行codex指令
我也搞不懂下一步怎么搞 所以说放在鸿蒙开发者论坛问一下大佬们
更多关于HarmonyOS鸿蒙Next中HNP打包问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
根据错误提示9568409 error:Failed to install the HAP because the extract of the native package failed,安装HAP时,提取native软件包失败
可能原因
HAP包中native软件包目录下不存在module.json5中配置的native软件包。
处理步骤
-
检查HAP包中的native软件包目录,重新打入需要安装的native软件包并完成签名或删除module.json5中缺失的native软件包配置信息。参考Native软件包开发指南。
-
【背景知识】
更多关于HarmonyOS鸿蒙Next中HNP打包问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
鸿蒙Next的HNP打包基于ArkTS语言实现,使用DevEco Studio的构建工具完成。打包过程包括模块编译、资源处理和签名验证。关键配置在module.json5中定义包名、版本和设备类型。遇到打包失败需检查依赖完整性、资源路径正确性及签名证书有效性。构建日志会明确指示错误位置,常见问题包括资源引用缺失或权限配置不当。
根据你的错误日志和配置,问题出现在HNP包安装过程中的原生包解压失败。以下是几个关键排查点:
-
HNP包结构验证
确保HNP包为标准的tar.gz格式,且内部结构符合规范。检查方法:tar -tzf codex.hnp应输出类似结构:
sysroot/bin/codex hnp.json -
hnp.json配置补全
当前配置文件缺少必要的入口声明。建议补充完整:{ "type": "hnp-config", "name": "codex", "version": "1.0", "install": { "binaries": [ { "source": "sysroot/bin/codex", "target": "bin/codex" } ] } } -
二进制文件兼容性
虽然你确认是aarch64静态链接,但需验证是否依赖未包含的动态库:file sysroot/bin/codex # 确认架构 readelf -d sysroot/bin/codex | grep NEEDED # 检查动态依赖 -
打包流程检查
在DevEco Studio中执行Build HAP时,确认:- HNP文件放置在
entry/src/main/resources/rawfile/目录 - module.json5中hnpPackages路径配置正确
- HNP文件放置在
-
设备环境匹配
确保测试设备系统版本支持HNP特性,且开发者模式已开启完整权限。
建议重新打包后使用命令行手动安装验证:
hdc shell bm install -p /path/to/your.hap
观察完整错误输出,若问题持续,可提供设备系统版本和DevEco Studio版本信息进一步分析。

