HarmonyOS 原有项目中flutter部分模块可以直接迁移至HarmonyOS项目中,作为一个模块吗?

如题:HarmonyOS 原有项目中flutter部分模块可以直接迁移至HarmonyOS项目中,作为一个模块吗?

阅读 574
1 个回答

可以将需要的模块打成har包,然后将har包作为模块,集成到项目中。

一、打包flutter模块:

1、创建flutter子模块工程:

flutter create -t module my_flutter_module 

2、编译生成 flutter\_module.har:

cd my_flutter_module flutter build har --local-engine=/Users/xxx/ohos/src/out/ohos_debug_unopt_arm64 --debug 

3、复制EntryAbility.ets和Index.ets到HarmonyOS项目MyApplication中:

cp my_flutter_module/.ohos/entry/src/main/ets/entryability/EntryAbility.ets MyApplication/entry/src/main/ets/entryability/EntryAbility.ets 
cp my_flutter_module/.ohos/entry/src/main/ets/pages/Index.ets MyApplication/entry/src/main/ets/pages/Index.ets 

二、在HarmonyOS工程中引用har包:

1、复制flutter\_module.har到HarmonyOS项目MyApplication:

cp my_flutter_module/.ohos/flutter_module/build/default/outputs/default/flutter_module.har MyApplication/har/flutter_module.har 

2、修改MyApplication/entry/oh-package.json5:

{
  // ...
  "dependencies": {
  "@ohos/flutter_module": "../har/flutter_module.har"
}
}

3、使用Deveco Studio配置MyApplication的签名。

4、运行MyApplication。

更多har包的详细使用请参考官网文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/har-package-V5

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进