HarmonyOS NEXT-Migrate the latest version of HarmonyOS from old versions (API19, modelVersion5.1.1)

2025/6/21, HarmonyOS recently released the latest API and modelVsersion, the emulator supports hot updates (hsp dynamic sharing packages are not supported), Build Analyzer supports viewing the memory consumption of the build process, and ignoreResourcePattern is added under buildOption/resOptions. It is used to filter the file/folder names under the resource directory resources or the resource directory defined by the developer, and the matching files will not be packaged into the product, and the ArkTS code debugging supports viewing the asynchronous function stack.
So how do you migrate updates? The next step is the manual migration and update tutorial, the modification is complete, click Sync to complete, and use the latest API19. (Taking the three-layer architecture path as an example, you can compare and see that the position is about the same)
Step 1:
Locate the file in the root directory at hvigor>>hvigor-config.json5 in the root directory
edit
Click on it and change the modelVersion to 5.1.1 as follows
edit
Step 2:
Locate the file in the root directory at root>build-profile.json5
edit
Click in, find the targetSdkVersion, compatibleSdkVersion in app, products, and modify it as follows
edit
Step 3: Locate the file in the root directory at the root directory > on-package.json5
edit
Click on it and change the modelVersion to 5.1.1 as follows
edit
Step 4: Click Sync Now in the upper right corner, run the code, and you can use API 19
edit
Tips:
In API 18, a lot of APIs are abandoned, please pay attention to API updates, but in ability, use windowStage.getMainWindowSync().getUIContext() official sample code (2025/6/21) to get the context, there will be an error, how to solve this problem, please use, the following code
windowStage.getMainWindow().then((win) => {
const uiContext = win.getUIContext()
// Store safe area data
AppStorage.setOrCreate<number>('safeTop', uiContext.px2vp(top.height))
AppStorageV2.connect(Number, 'safeTop', () => new Number(uiContext.px2vp(top.height)))
AppStorage.setOrCreate<number>('safeBottom', uiContext.px2vp(bottom.height))
AppStorageV2.connect(Number, 'safeBottom', () => new Number(uiContext.px2vp(bottom.height)))
})
To avoid the program not running, AppStorageV2.connect(UIContext,'uiContext',()=>new UIContext())?. getHostContext(), to get the context in the ability can only get empty, can only use the solution I provided, for specific details, please refer to another article in the document HarmonyOS NEXT-API19 to get the context, get the context in class and ability, API migration example - solve the problem that you can't use the latest version of the API to get the context in EntryAbility.
Subscribe to my newsletter
Read articles from xiao directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
