How Generative AI Can Accelerate HarmonyOS Development with AutoDev
This article explores how generative AI is integrated into the AutoDev tool to add ArkTS language support, automatically generate ArkUI pages, and migrate existing Android, iOS, and mini‑program code to HarmonyOS, while discussing technical challenges and future improvements.
Why Combine Generative AI with HarmonyOS?
Generative AI offers huge potential for software R&D and knowledge management, prompting many enterprises to adopt it. HarmonyOS introduces new concepts, the DevEco Studio IDE, the ArkTS language, and the ArkUI declarative UI framework, making it a natural candidate for AI‑assisted development.
Experimentation in AutoDev
AutoDev was used to explore three experimental features that aim to lower developers' learning burden while leveraging AI:
Add ArkTS language support – ArkTS is a TypeScript‑based language for HarmonyOS.
Automatic ArkUI page generation – ArkUI is a declarative UI framework for distributed applications.
UI layout migration – Convert code written in other languages or frameworks into HarmonyOS‑compatible code.
1. AI Support for the ArkTS Language
After installing DevEco Studio, it was discovered that AutoDev did not recognize TypeScript. Investigation with the PSIViewer plugin revealed that DevEco Studio implements its own JavaScript/TypeScript module, e.g.:
com.huawei.ace.language.psi.impl.JavaScriptIdentifierNameImplThe reasons are twofold: the IntelliJ JavaScript plugin is commercial, and HarmonyOS extends the TypeScript syntax directly, making a custom implementation simpler.
Consequently, DevEco Studio adds a JavaScript/TypeScript module that provides syntax highlighting, code completion, and formatting, and also introduces the ArkTS language as an extension of TypeScript. This creates three new file types in the IDE: Huawei JavaScript, Huawei TypeScript, and Huawei ArkTS.
To enable AI‑driven support, AutoDev abstracts the standard PSI via reflection and integrates it with DevEco Studio’s JavaScript support. The intended steps are:
Reuse the existing JavaScript PSI through reflection.
Integrate the DevEco Studio JavaScript capabilities.
Because debugging proved difficult, the approach was temporarily abandoned, assuming the HarmonyOS IDE will eventually provide its own AI capabilities.
2. AutoArkUI: RAG‑Enhanced ArkUI Code Generation
ArkUI is a declarative UI framework for building distributed application interfaces. Generating ArkUI code is slightly more complex than generating ArkTS code, so the current strategy focuses on classic UI element generation.
Layouts: linear (Row, Column), stack, flex, etc.
Components: Button, Radio, Toggle, and similar widgets.
Because ChatGPT lacks up‑to‑date HarmonyOS knowledge, a two‑step generation process similar to AutoPage is used:
Analyze the user's requirements and select appropriate layouts and components.
Generate the corresponding ArkUI code based on the detailed layout and component information.
The prompt for step 1 looks like:
User: // maybe send Android Layout code, maybe some requirements
Your Answer: [FlexLayout, Button, CheckBox, Checkbox, Button]
To avoid generating Chinese DSL, the prompts are written in English.
3. Migrating Android/iOS/Mini‑Program Apps
Generative AI excels at code translation, as demonstrated by IBM’s Cobol‑to‑Java project and AutoDev’s legacy‑system transformation capabilities. AutoDev currently supports only layout migration for HarmonyOS, but acknowledges many open issues that need further research.
4. RAG‑Enhanced Chat Context for C++ NAPI and Others
Experiments showed that ChatGPT does not know HarmonyOS‑specific knowledge, so a custom context is injected via AutoDev. The project includes a placeholder comment: This project is a HarmonyOS project. Two context blocks are defined:
TypeScript/JavaScript/ArkTS : Treat the project like a Flutter‑style declarative UI framework.
C++/NAPI : Use C++ as the main language and NAPI for building native addons.
Guidelines for the AI include:
When writing ArkUI or front‑end code, consider the project similar to a Flutter declarative UI.
When writing native code, treat the project as based on NAPI for plugin development.
Future Work and Current Limitations
The features described were built within a few hours, so expectations should be modest. Current shortcomings include:
Android layout conversion often produces incorrect code due to missing conversion rules and property knowledge.
Hard‑coded component and layout information.
Lack of dynamic example code, limiting RAG effectiveness.
Missing support for C++ language.
Conversion of WeChat mini‑programs and other platforms.
The author is not an expert in migrating Android or mini‑program apps to HarmonyOS, so further challenges remain. Improvements will be pursued when time permits.
phodal
A prolific open-source contributor who constantly starts new projects. Passionate about sharing software development insights to help developers improve their KPIs. Currently active in IDEs, graphics engines, and compiler technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
