Detailed Guide to Developing Flutter Plugins for HarmonyOS
0. Environment Setup
Prerequisite: Configure HarmonyOS Flutter environment
Reference: HarmonyOS Flutter Environment Setup Guide
Note: Downloading and compiling the engine is time-consuming. Pre-built engines are available upon request.
1. Obtain Original Plugin Code
git clone <original_plugin_repository>
2. Generate OHOS Directory
# Option 1: Direct generation (may fail)
flutter create -t plugin --platforms ohos
# Option 2: Create demo project and copy
flutter create -t plugin --platforms ohos demo
cp -r demo/ohos ./
3. Configure Local Dependency
Add local dependency in pubspec.yaml:
dependencies:
your_plugin:
path: ../path_to_plugin
4. Build Plugin Package
flutter build hap \
--local-engine-src-path /path/to/ohos_flutter/src \
--local-engine ohos_release_arm64
Successful Output:
√ Built build/hap/release/entry-release.hap (XX.XMB)
5. Verify Generated Files
After successful build:
6. Locate Plugin HAR Package
Plugin output directory:
your_plugin/ohos/build/outputs/
└── har
└── your_plugin_ohos.har # Plugin package
7. Add HAR to Demo Project
Copy HAR to demo project:
bash
cp your_plugin_ohos.har demo_portal/module/ohos/libs/
8. Configure HAR Dependency
9. Initialize Plugin
10. Test Plugin Functionality
11. Develop Native Implementation
Follow these steps for native development:
- Analyze existing iOS/Android native logic
- Create HarmonyOS equivalent in
ohos/src/main/cpp/ - Implement platform interface:cpp








Top comments (0)