How do I create a Flutter app for HarmonyOS?

Published:

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

fluttertutorialharmonyos

Short answer: Flutter does not run on HarmonyOS with the standard SDK. Clone the OpenHarmony-adapted Flutter fork from GitCode, check out a release branch, set a few environment variables, and create your project with flutter create --platforms ohos. Then use flutter run for development and flutter build hap --release for a package.

What is Flutter for HarmonyOS?

The community-maintained CPF-Flutter organization on GitCode hosts a Flutter fork that adds an ohos target (a Flutter engine and tool that produce HarmonyOS/OpenHarmony apps). Your Dart code and widgets stay the same. The platform layer, written in ArkTS, replaces the Android/iOS embedders.

What do you need first?

How do I set up the Flutter fork?

Clone the repository and check out a release branch:

git clone https://gitcode.com/CPF-Flutter/flutter_flutter.git
cd flutter_flutter
git checkout oh-3.35.7-release

Set the environment variables (the storage and pub mirrors are hosted in China):

export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com
export PUB_HOSTED_URL=https://repo.huaweicloud.com
export HOS_SDK_HOME=/path/to/ohos-sdk
export OHOS_SDK_HOME=$HOS_SDK_HOME
export PATH=$PATH:/path/to/flutter_flutter/bin

Then verify the setup:

flutter doctor

Troubleshooting notes from the project documentation:

  • “The SDK license agreement is not accepted”: run ./ohsdkmgr install --accept-license.
  • After changing FLUTTER_STORAGE_BASE_URL, delete bin/cache.
  • Run flutter clean after changing the environment.

How do I create and run the app?

flutter create --platforms ohos,android,ios --org com.example myapp
cd myapp
flutter run --debug

The ohos directory in the project is a normal HarmonyOS project that DevEco Studio can open. Hot reload works as in regular Flutter. Running on a physical device needs a signing configuration; see the signing step in Your first ArkTS app.

For a plugin or an add-to-app module:

flutter create -t plugin --platforms ohos my_plugin
flutter create -t module my_module

How do I build a package?

flutter build hap --release
flutter install -t <deviceId> <hap_file_path>

What is in the CPF-Flutter organization?

Page 2 of the organization’s repository list contains, among others:

RepositoryPurpose
flutter_samplesFlutter’s official samples extended with OpenHarmony adaptation and docs (60+ samples)
fluttertpc_file_pickerNative file manager picker with extension filtering
fluttertpc_file_previewFile preview plugin
fluttertpc_video_thumbnailThumbnails from video files
fluttertpc_flutter_zxingBarcode and QR scanning and generation (ZXing)
fluttertpc_flutter_webrtcWebRTC
fluttertpc_agora_rtc_engineLive interaction and audio playback with Agora
fluttertpc_audio_service, flutter_audioplayers, flutter_audio_sessionAudio playback and sessions
fluttertpc_tts_pluginText to speech
fluttertpc_wifi_iotWi-Fi connection and hotspot (AP, STA)
fluttertpc_flutter_downloaderDownload task management
fluttertpc_FlutterUpgraderApp upgrade
fluttertpc_flutter_keychainSecure storage
fluttertpc_angleANGLE: OpenGL ES calls translated to Vulkan
flutter_multidevice_layout_scenepkgLayout adaptation for foldables, tablets and phones

Plugin names and versions change often, so check each repository’s README before adding it to pubspec.yaml.

Next steps

Frequently asked questions

Can I use the standard Flutter SDK for HarmonyOS?

No. The official Flutter SDK does not include an ohos platform. You need the OpenHarmony-adapted Flutter fork, which is hosted on GitCode (CPF-Flutter/flutter_flutter).

Which Flutter versions are supported?

The fork's documentation lists 3.35.7, 3.27.4, 3.22.0 and 3.7.12, with a branch such as oh-3.35.7-release and version tags such as 3.35.8-ohos-1.0.4.

How do I create a project that targets HarmonyOS?

Run flutter create --platforms ohos,android,ios --org com.example myapp using the fork's flutter binary. The ohos platform adds an ohos directory to the project.

How do I build a release package?

Run flutter build hap --release. Install the resulting HAP on a device with flutter install -t <deviceId> <hap_file_path>.

Where do I find plugins that work on HarmonyOS?

The CPF-Flutter organization on GitCode hosts OpenHarmony-adapted plugins (file_picker, video_thumbnail, flutter_zxing, flutter_webrtc and more) and flutter_samples with 60+ examples.