手记

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

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

老卫

2实战 · 246手记 · 2推荐

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

设置targetSdkVersion



点第二项。

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,会自动做如下更改:

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




点击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)


0人推荐
随时随地看视频
慕课网APP