English | 简体中文
A HarmonyOS Application Package (HAP) project based on the HarmonyOS platform that enables running Electron applications on HarmonyOS devices.
ohos_electron_hap/
├── AppScope/ # Application scope configuration
├── chromium/ # Chromium module
├── electron/ # Electron main module
├── web_engine/ # Web engine component
├── hvigor/ # Build tool configuration
├── build-profile.json5 # Project build configuration
├── hvigorfile.ts # Build script
└── oh-package.json5 # Project dependencies configuration
- DevEco Studio: 4.0 or higher
- HarmonyOS SDK: API Level 10 or higher
- Node.js: 16.x or higher
- HDC Tool: For device debugging and installation
Before starting the build, you need to prepare the following resources:
Place your Electron application code (compiled artifacts) into:
web_engine/src/main/resources/resfile/resources/app/
- Open the project with DevEco Studio
- Select Build → Build Hap(s)/APP(s) → Build Hap(s)
- Or click the run button in the top right corner to launch the application
After building, the unsigned HAP package will be saved at:
electron/build/default/outputs/default/electron-default-unsigned.hap
To run normally on devices, the HAP package needs to be signed:
Recommend using automatic signature verification
- Apply for Huawei Developer Certificate
- Configure signing information in DevEco Studio
- Rebuild to generate signed HAP package
For detailed signing process, please refer to: Application/Service Signing-DevEco Studio
Click the run button directly to install on device
hdc app install <signed-hap-package-path>
# Example: hdc app install electron-default-signed.hapEdit file: electron/src/main/resources/zh_CN/element/string.json
{
"string": [
{
"name": "EntryAbility_label",
"value": "Your Application Name"
}
]
}Place new icon file into: AppScope/resources/base/media/
Edit electron/src/main/module.json5, add metadata in abilities:
"metadata": [
{
"name": "ohos.ability.window.height",
"value": "800"
},
{
"name": "ohos.ability.window.width",
"value": "800"
},
{
"name": "ohos.ability.window.left",
"value": "center"
},
{
"name": "ohos.ability.window.top",
"value": "center"
}
]Application permissions are configured in the requestPermissions field of the web_engine/src/main/module.json5 file.
ohos.permission.INTERNET- Network accessohos.permission.GET_NETWORK_INFO- Get network informationohos.permission.RUNNING_LOCK- Background running lockohos.permission.PREPARE_APP_TERMINATE- Application termination preparation
ohos.permission.CAMERA- Camera permissionohos.permission.MICROPHONE- Microphone permissionohos.permission.LOCATION- Location permissionohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY- Download directory access
const { BrowserWindow } = require('electron');
let floatWindow = new BrowserWindow({
windowInfo: {
type: 'floatWindow' // mainWindow, subWindow, floatWindow
},
parent: mainWindow,
x: 100,
y: 100,
width: 800,
height: 600,
transparent: true, // Transparent window
opacity: 0.5 // Opacity
});const { systemPreferences } = require('electron');
// Request camera permission
systemPreferences.requestSystemPermission('camera').then(granted => {
console.log('Camera permission:', granted);
});
// Request directory permission
systemPreferences.requestDirectoryPermission(null).then(granted => {
console.log('Directory permission:', granted);
});const { BrowserWindow } = require('electron');
const win = new BrowserWindow();
win.webContents.openDevTools();- Add debugging parameters in
web_engine/src/main/ets/components/WebWindow.ets:
let inspect = '--inspect=9229';
let vec_args = [..., inspect];- Configure port forwarding:
hdc fport tcp:9229 tcp:9229- Access in Chrome browser:
chrome://inspect
- User data stored by default at:
/data/storage/el2/base/files - Application installation directory:
/data/storage/el1/bundle - Database directory:
/data/storage/el2/database
- Check if SO library files are complete
- Confirm Electron application code is correctly placed
- Verify permission configuration is correct
- C++ addon: Need to recompile for HarmonyOS platform adaptation
- Platform detection: Need to adapt
process.platform === 'ohos' - Binary files: May need to replace with HarmonyOS versions
If certain ACL permissions cannot be obtained, you can temporarily comment out related permissions:
// "requestPermissions": [
// {
// "name": "ohos.permission.SYSTEM_FLOAT_WINDOW"
// }
// ]- Fork this repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/your-feature - Submit a Pull Request
If you encounter issues or need support, please submit an Issue or contact the maintenance team.