OpenHarmony
Prerequisites
- First, add the
ohosRust target. If you have not installedcargoyet, follow the official Rust guide to install the build tools for your system.
For more information, see ohos-rs.
rustup target add aarch64-unknown-linux-ohos
rustup target add armv7-unknown-linux-ohos # theoretically optional
rustup target add x86_64-unknown-linux-ohos # theoretically optional, unless running on x86 emulator- Download the latest
DevEco Studioand install the correspondingNDK. You can get it from DevEco Studio (Windows/macOS) or use Command Line Tools (recommended for Linux).
After installation, set an environment variable to help build the native module. Assuming your SDK is installed at /path/Sdk:
| Platform | NDK Path | How to Set |
|---|---|---|
| macOS | /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony | Run in terminal:export OHOS_NDK_HOME=/Applications/DevEco-Studio.app/Contents/sdk/default/openharmonyAdd to ~/.zshrc or ~/.bash_profile to make it permanent |
| Windows | C:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony | 1. Open System Environment Variables 2. Create a new system variable OHOS_NDK_HOME3. Set the value to the path above Or set temporarily in PowerShell: $env:OHOS_NDK_HOME="C:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony" |
| Linux | Custom path after installing Command Line Tools | Run in terminal:export OHOS_NDK_HOME=/your/download/path/openharmonyAdd to ~/.bashrc or ~/.profile to make it permanent |
Note:
DevEco StudioorCommand Line Toolsmust be version 6.0.0 (API 20) or later. On macOS, only Apple Silicon is recommended for development.
- Install
ohrs:
cargo install ohrsBuilding
- Clone the repositories first.
git clone https://github.com/TeamFlos/phira
git clone https://github.com/TeamFlos/phira-ohosFor the static library, download
aarch64-unknown-linux-ohos.tar.gzfrom prpr-avc-ffmpeg, then extract all*.afiles intophira/prpr-avc/static-lib/aarch64-unknown-linux-ohos.Add
config.tomlto configure thecmakelocation. This is required to compile Phira for theohostarget.
$ cd phiraFor Linux:
.cargo/config.toml
[env]
CMAKE = "/your/ohos/sdk/command-line-tools/sdk/default/openharmony/native/build-tools/cmake/bin/cmake"
CMAKE_TOOLCHAIN_FILE_aarch64-unknown-linux-ohos = "/your/ohos/sdk/command-line-tools/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake"
CMAKE_GENERATOR = "Ninja"
CMAKE_MAKE_PROGRAM = "/your/ohos/sdk/command-line-tools/sdk/default/openharmony/native/build-tools/cmake/bin/ninja"
OHOS_NDK_HOME = "/your/ohos/sdk/command-line-tools/sdk/default/openharmony"For Windows, create cmake-wrapper.cmd inside the project's .cargo folder. Temporary variables are used here to avoid conflicts with the system's default cmake:
.cargo/cmake-wrapper.cmd
@echo off
set PATH=D:/your/ohos/sdk/default/openharmony/native/build-tools/cmake/bin;%PATH%
"D:/your/ohos/sdk/default/openharmony/native/build-tools/cmake/bin/cmake.exe" %*.cargo/config.toml
[env]
CMAKE = "your/project/path/.cargo/cmake-wrapper.cmd"
CMAKE_TOOLCHAIN_FILE_aarch64-unknown-linux-ohos = "D:/your/ohos/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake"
CMAKE_GENERATOR = "Ninja"
CMAKE_MAKE_PROGRAM = "D:/your/ohos/sdk/default/openharmony/native/build-tools/cmake/bin/ninja.exe"- Start the build:
phira> cd phira # You must enter the phira subfolder, otherwise no build output will be generated
phira/phira> ohrs build --release --arch aarch # You can omit --arch to build x86_64, armv7, and arm64 together, but current HarmonyOS devices are arm64After the build succeeds,
libphira.sowill be located inphira/dist/<arch>.The
phira-ohosrepository does not include resource files. Copy theassets/folder toentry/src/main/resources/resfile/assetsin advance. If the app shows a black screen, go to the Releases page, download any version, and copy the missing resource files into the same directory.Enter the
phira-ohosfolder, renamebuild-profile-nosigncfg.json5tobuild-profile.json5, and then open it inDevEco Studio.
Connect your device, open Project Structure, find Signing configs, select Automatically generate signature, and click Apply. The project will then sync automatically.

The arrow shows where Project Structure is located.
Copy the generated libphira.so into entry/libs/arm64-v8a. Then click Build to run it on a HarmonyOS device.
Troubleshooting
If you run into very strange build errors, consider switching to WSL, or even ARM macOS, for compilation.
DevEco Studio does not have a native Linux version.