HarmonyOS鸿蒙Next中hap打包

HarmonyOS鸿蒙Next中hap打包 怎么打包正式的hap? deveco 5.0.0

6 回复

1、先将 Build Model 设置为 release

2、在 Build 菜单栏上选择 Build Hap

如果遇到签名问题,请先配置好签名

修改工程目录下 build-profile.json5 ->

"signingConfig": "default", //设置为 signingConfigs 中对应的正式签名配置

![cke_135.png](data-originheight=“658” data-originwidth=“942” height=“296” src=“https://alliance-communityfile-drcn.dbankcdn.com/FileServer/getFile/cmtybbs/769/784/281/0030086000769784281.20250724181218.56910991663198310468633988614724:50001231000000:2800:00F3C7DAF4D9C25863B7C7436137C60A7239A9723B9D8264DF02D1CEF2017B4A.png” style=“width: 424.0px;height: 296.0px;” width=“424”)

![cke_502.png](data-originheight=“424” data-originwidth=“660” height=“279” src=“https://alliance-communityfile-drcn.dbankcdn.com/FileServer/getFile/cmtybbs/769/784/281/0030086000769784281.20250724181238.32776957591401551790910121542123:50001231000000:2800:7F48E28C44984438B310DB0F05533940255913259C9E2B215CDFC80D858EC51C.png” style=“width: 435.0px;height: 279.0px;” width=“435”)

更多关于HarmonyOS鸿蒙Next中hap打包的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


  • iconId: 16777228
  • debug: true
  • minAPIVersion: 50000012
  • icon: $media:icon_logo
  • label: $string:app_name
  • bundleType: app
  • versionName: 1.0.0
  • versionCode: 1
  • appEnvironments: []
  • compileSdkType: HarmonyOS
  • labelId: 16777216
  • compileSdkVersion: 5.0.0.71
  • targetAPIVersion: 50000012
  • vendor: shineiot
  • bundleName: com.shineiot.ydbg
  • apiReleaseType: Release

那你直接选下一个,Build APP(s), 打app包。再将.app 改为 zip。解压出来看看里面的 .hap。

这个debug代表的调试模式,是不是与调试证书有关系?

判断测试环境还是正式环境还得使用BuildProfile.BUILD_MODE_NAME

鸿蒙Next中hap打包使用hvigor工具替代了传统的webpack。开发者需在项目根目录的build-profile.json5中配置打包参数,包括"targets"指定输出类型(如default、ohosTest)。通过执行hvigor assemble命令生成HAP包。HAP包分为entry(主模块)和feature(特性模块),每个模块需单独配置module.json5文件定义能力。打包产物存储在工程目录的build/outputs目录下,包含debug和release两种模式。

在HarmonyOS Next中使用DevEco Studio 5.0.0打包正式HAP的步骤如下:

  1. 确保项目配置正确:
  • 检查build-profile.json中的"releaseType"设置为"release"
  • 确认签名配置已完成(需提前申请发布证书)
  1. 打包流程:
  • 在DevEco Studio顶部菜单选择Build > Build Hap(s)/App(s) > Build Release Hap(s)
  • 或直接使用Gradle命令:./gradlew assembleRelease
  1. 输出位置:
  • 生成的HAP文件默认在/build/outputs/hap/release/目录下
  1. 注意事项:
  • 正式HAP必须使用发布证书签名
  • 确保minAPIVersion等兼容性配置正确
  • 如需上架应用市场,建议同时生成.app格式的包

(注:实际操作可能因项目配置略有差异),

回到顶部