HarmonyOS鸿蒙Next社区的Flutter版本只支持HarmonyOS Next,不支持OpenHarmony吗?
HarmonyOS鸿蒙Next社区的Flutter版本只支持HarmonyOS Next,不支持OpenHarmony吗?
版本信息
flutter doctor -v
[!] Flutter (Channel [user-branch], 3.22.1-ohos-1.0.0, on macOS 13.7.6 22H625 darwin-x64, locale zh-Hans-CN)
! Flutter version 3.22.1-ohos-1.0.0 on channel [user-branch] at /Users/kai/.flutter/oh_flutter_3.22
Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
• Upstream repository https://gitcode.com/openharmony-sig/flutter_flutter.git
• FLUTTER_GIT_URL = https://gitcode.com/openharmony-sig/flutter_flutter.git
• Framework revision a241f514ed (6 days ago), 2025-05-13 22:36:57 +0800
• Engine revision f6344b75dc
• Dart version 3.4.0
• DevTools version 2.34.1
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks
and upgrades.
[✓] HarmonyOS toolchain - develop for HarmonyOS devices
• OpenHarmony Sdk at /Applications/DevEco-Studio.app/Contents/sdk, available api versions has [17:default]
• Ohpm version 5.0.16
• Node version v18.20.1
• Hvigorw binary at /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw
....
[✓] VS Code (version 1.100.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.110.0
[✓] Connected device (3 available)
• 0091806808244b10 (mobile) • 0091806808244b10 • ohos-arm64 • Ohos OpenHarmony-5.0.0.71 (API 12)
• macOS (desktop) • macos • darwin-x64 • macOS 13.7.6 22H625 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 136.0.7103.114
[✓] Network resources
• All expected network resources are available.
启动直接闪退:
Device info:移动数据终端
Build info:OpenHarmony 5.0.0.707
Fingerprint:7464bb1309dcae4356b6db0283b8825d81fe25bf1c13802bab99e43e29af6cba
Module name:com.example.ohos_app
Version:1.0.0
VersionCode:1
PreInstalled:No
Foreground:Yes
Pid:26727
Uid:20010053
Reason:TypeError
Error name:TypeError
Error message:Cannot read property nativeInit of undefined
Stacktrace:
at init (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterNapi.ets:94:31)
at ensureInitializationComplete (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/loader/FlutterLoader.ets:268:5)
at checkLoader (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngineGroup.ets:36:7)
at setupFlutterEngine (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets:223:7)
at onAttach (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets:68:7)
at onCreate (oh_modules/.ohpm/@ohos+flutter_ohos@9kqpxxvrkevrqywwhtpiewkd1pgqyw5lf7dxvh2sbiq=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/ohos/FlutterAbility.ets:78:5)
定位到代码
ohos/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterNapi.ets
更多关于HarmonyOS鸿蒙Next社区的Flutter版本只支持HarmonyOS Next,不支持OpenHarmony吗?的实战教程也可以访问 https://www.itying.com/category-92-b0.html
Mark
更多关于HarmonyOS鸿蒙Next社区的Flutter版本只支持HarmonyOS Next,不支持OpenHarmony吗?的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
姐妹,遇到了相同的问题,升级SDK 和,安装到模拟器上就闪退,,我还怀疑是第三方的问题,重新生成的项目也是这个错
目前Flutter对HarmonyOS的支持情况如下:
-
Flutter官方尚未正式支持OpenHarmony
-
华为提供的HarmonyOS Next Flutter插件仅针对HarmonyOS Next平台
-
OpenHarmony需要第三方适配方案或等待Flutter官方支持
-
两者架构差异导致不能直接兼容,
根据错误信息和代码分析,当前Flutter for OpenHarmony版本存在兼容性问题。错误"TypeError: Cannot read property nativeInit of undefined"表明Flutter引擎未能正确初始化,这通常是由于底层native库加载失败导致的。
从技术实现来看,Flutter for OpenHarmony和HarmonyOS Next是两个不同的分支。目前社区维护的OpenHarmony版本(如您使用的3.22.1-ohos-1.0.0)与HarmonyOS Next的Flutter支持并不完全兼容。
建议检查以下几点:
- 确保设备已正确安装所需的native库
- 确认Flutter SDK路径配置正确
- 检查项目依赖的flutter_ohos版本是否与SDK版本匹配
当前问题更可能是OpenHarmony平台适配不完善导致的,建议关注OpenHarmony SIG的Flutter适配进展。