继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

如何将鸿蒙5应用升级到鸿蒙6

2025-09-29 09:21:5231浏览

老卫

2实战 · 246手记 · 2推荐
TA的实战

如何将鸿蒙5应用升级到鸿蒙6

设置targetSdkVersion

https://img1.sycdn.imooc.com/e3ac1a6809d9dd8417701196.jpg



点第二项。

build-profile.json5改为了如下:



{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true
}
},
"targetSdkVersion": "6.0.0(20)"
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}






升级modelVersion

点击Migrate Assistant,会自动做如下更改:

https://img1.sycdn.imooc.com/f257dc6809d9dd8908880656.jpg

To start migration, select the version to which you want to migrate this project (in both hvigor and ohpm) and click Migrate.


This migration will lead to the following changes:

1. Upgrade hvigor modelVersion from 5.0.0 to 6.0.0

2. Upgrade ohpm modelVersion from 5.0.0 to 6.0.0


https://img1.sycdn.imooc.com/6319226809d9dd8f11680397.jpg



点击Migrate


oh-package.json5会自动改为了如下:


{
"modelVersion": "6.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
"@ohos/hypium": "1.0.19",
"@ohos/hamock": "1.0.0"
}
}



代码整改



查看编译情况,关注控制台日志。如果有报错,根据提示进行整改。


常见的问题是,鸿蒙6的ArkTS语言语法规则更加严格,

因此,需要做一些判空处理或者是类型指定等。


视频演示


详见B站:https://www.bilibili.com/video/BV1yBHwzDEkK/


参考引用


• 本文同步至:https://waylau.com/upgrade-harmonyos-app-version-from-5-to-6/

• 源码见《跟老卫学HarmonyOS开发》开源免费教程, https://github.com/waylau/harmonyos-tutorial

• 《跟老卫学AI大模型开发》开源免费教程, https://github.com/waylau/ai-large-model-tutorial/

• 《跟老卫学仓颉编程语言开发》开源免费教程, https://github.com/waylau/cangjie-programming-language-tutorial

• 《鸿蒙HarmonyOS手机应用开发实战》(清华大学出版社)

• 《鸿蒙HarmonyOS应用开发入门》(清华大学出版社)

• “鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”(https://coding.imooc.com/class/843.html)

• 《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》(北京大学出版社)

• 《鸿蒙之光HarmonyOS NEXT原生应用开发入门》(清华大学出版社)

• “HarmonyOS NEXT+AI大模型打造智能助手APP(仓颉版)”(https://coding.imooc.com/class/927.html)


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP