How do I run an Electron app on HarmonyOS?

Published:

✓ Verified: · OpenHarmony 6.1.1 Release, API 24 · Author: Ohosify

electrontutorialharmonyos

Short answer: Clone the ohos_electron_hap template, open it in DevEco Studio, copy your compiled Electron app into web_engine/src/main/resources/resfile/resources/app/, configure signing, build the HAP, and install it with hdc app install.

What is ohos_electron_hap?

It is a template project that packages Electron applications as HarmonyOS HAP files. The README describes a complete toolchain with support for floating windows, system permissions and multi-window coordination. It does not state which Electron version it is based on, so check the repository before you depend on a specific one.

What do you need first?

RequirementVersion (from the README)
DevEco Studio4.0 or later
HarmonyOS SDKAPI level 10 or later
Node.js16.x or later
hdcFor device install and debugging

See How to install DevEco Studio and the hdc command guide.

What is in the project?

AppScope/          application configuration
chromium/          Chromium module
electron/          main Electron module
web_engine/        web engine component
hvigor/            build tool configuration
build-profile.json5, hvigorfile.ts, oh-package.json5

How do I add my app?

Build your Electron app as usual, then put the compiled output in:

web_engine/src/main/resources/resfile/resources/app/

How do I build, sign and install?

  1. Open the project in DevEco Studio.

  2. Configure signing. A device needs a signed package, which requires a Huawei developer certificate configured in DevEco Studio. Do this before rebuilding.

  3. Choose Build > Build Hap(s). The unsigned output is at electron/build/default/outputs/default/electron-default-unsigned.hap.

  4. Install the signed package:

    hdc app install <signed-hap-package-path>

What HarmonyOS-specific features exist?

  • Floating windows: create a window with type: 'floatWindow'.
  • System permission requests through systemPreferences.
  • Platform detection: process.platform === 'ohos'.

What are the limitations?

  • C++ Node addons must be recompiled for HarmonyOS.
  • Third-party binary files may need HarmonyOS versions. For CLI tools, see how to cross-compile and package them as HNP.
  • Some ACL permissions may need to be commented out temporarily, according to the README.

Next steps

Frequently asked questions

What is ohos_electron_hap?

It is a template project that lets Electron applications run on HarmonyOS devices as HAP packages. It includes a Chromium module, an Electron module and a web engine module.

What are the requirements?

According to the README: DevEco Studio 4.0 or later, HarmonyOS SDK API level 10 or later, Node.js 16.x or later, and the hdc tool for installing and debugging on a device.

Where do I put my Electron app?

Place the compiled Electron artifacts in web_engine/src/main/resources/resfile/resources/app/ inside the project.

How do I detect HarmonyOS in my code?

Check process.platform === 'ohos'.

Can I use native Node addons?

Only after recompiling them for HarmonyOS. The README states that C++ addons need to be recompiled, and that third-party binaries may need HarmonyOS builds.