Quick Start Guide for Developing HarmonyOS Native Apps with Taro
This guide provides a step‑by‑step tutorial on configuring the development environment, installing Taro v4 beta, setting up the HarmonyOS project in DevEco Studio, and using Taro plugins and scripts to build, preview, and debug native HarmonyOS applications.
This guide introduces developers to using the Taro framework for rapid development of native HarmonyOS applications, explaining how Taro enables a single codebase to target multiple platforms, including HarmonyOS.
Environment Configuration – Install and configure Huawei DevEco Studio, create a new HarmonyOS project, apply for the whitelist, and set up the SDK path. Ensure the SDK version matches API 10.
Project Setup – Create the HarmonyOS main project, familiarize with the directory structure (e.g., entry/src/main/ets/pages/Index.ets ), and add the required Taro plugin.
Install Taro CLI – Run npm i -g @tarojs/cli@beta to install the beta version of the Taro command‑line tool.
Install Project Dependencies – For new projects use the Vite template; for existing projects install Vite, Terser, and the Taro Vite runner:
npm i vite@^4.2.0 npm i terser@^5.4.0 npm i @tarojs/vite-runner@beta
Install HarmonyOS Plugin – Add the Harmony plugin with npm i @tarojs/plugin-platform-harmony-ets@beta .
Modify Taro Configuration – In config/index.ts enable the plugin and set Harmony options, including the compiler (Vite), project path, HAP name, and module name.
Configure Permissions – Edit entry/src/main/module.json5 to request necessary permissions such as VIBRATE, INTERNET, and LOCATION.
Build and Run – Add scripts to package.json :
"scripts": { "build:harmony": "taro build --type harmony", "dev:harmony": "npm run build:harmony -- --watch" }
Preview & Debug – Use Huawei test devices for preview and debugging; simulators are not yet supported. Connect the device, enable developer mode, and run the scripts to view the app on the device.
Notes – Discuss style limitations (no box model, only Flex/Column), supported units (px, vw, vh), and differences from mini‑programs such as unavailable APIs and component restrictions.
Conclusion – By following this guide, developers can quickly set up the environment, configure Taro, and start building HarmonyOS applications, gaining cross‑platform development experience.
JD Tech
Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.
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.