写点什么

ohos 开发 flutter_module

作者:flfljh
  • 2024-11-07
    湖南
  • 本文字数:1271 字

    阅读完需:约 4 分钟

ohos 开发 flutter_module

1.DevEco-Studio 搭建原生工程

使用 [flutter_flutter](https://gitee.com/openharmony-sig/flutter_flutter),配置相关的环境变量
使用 [flutter_engine](https://gitee.com/openharmony-sig/flutter_engine) 生成的engine产物
复制代码

2.搭建 flutter_module 工程

# 1. 创建 flutter子模块工程flutter create -t module my_flutter_module# 2. 编译生成 flutter_module.harcd my_flutter_moduleflutter build har --debugcd -# 3. 复制 EntryAbility.ets 和 Index.ets 到 MyApplication 中cp my_flutter_module/.ohos/entry/src/main/ets/entryability/EntryAbility.ets MyApplication/entry/src/main/ets/entryability/EntryAbility.etscp my_flutter_module/.ohos/entry/src/main/ets/pages/Index.ets MyApplication/entry/src/main/ets/pages/Index.ets
复制代码

ohos 工程引用 flutter

ohos 工程引用 flutter 工程有两种使用方式

方式一:ohos 工程 引用 har 文件

1. 复制 har 文件

cp -r my_flutter_module/.ohos/har/* MyApplication/har/
复制代码

2. 修改 MyApplication/oh-package.json5

{  // ...  "dependencies": {    "flutter_module": "har/flutter_module.har"  },  "overrides": {    // 有冲突的依赖需要放到这里消除冲突    "@ohos/flutter_ohos": "har/flutter.har",    "plugin_xxx": "har/plugin_xxx.har"  }}
复制代码

3. 使用 Deveco Studio 配置 MyApplication 的签名

4. 运行 MyApplication

方式二:ohos 工程 直接引用 flutter_module 源码

1. 复制 flutter_module 源码 和 flutter 相关文件

cp -r my_flutter_module/.ohos/flutter_module MyApplication/mkdir -p MyApplication/flutter_module/src/main/resources/rawfilecp -r my_flutter_module/.ohos/flutter_module/src/main/resources/rawfile/flutter_assets MyApplication/flutter_module/src/main/resources/rawfilecp my_flutter_module/.ohos/har/flutter.har MyApplication/har/flutter.har
复制代码

2. 修改 MyApplication/build-profile.json5

{  // ...  "modules": [    {      "name": "entry",      "srcPath": "./entry",      "targets": [        {          "name": "default",          "applyToProducts": [            "default"          ]        }      ]    },    // 以下为新增内容    {      "name": "flutter_module",      "srcPath": "./flutter_module",      "targets": [        {          "name": "default",          "applyToProducts": [            "default"          ]        }      ]    }  ]}
复制代码

3. 修改 MyApplication/oh-package.json5

{  // ...  "dependencies": {    "flutter_module": "./flutter_module",    "@ohos/flutter_ohos": "./har/flutter.har"  },  "overrides": {    "@ohos/flutter_ohos": "./har/flutter.har"  }}
复制代码

4. 使用 Deveco Studio 配置 MyApplication 的签名

5. 运行 MyApplication


结束语结束语结束语结束语结束语结束语结束语结束语结束语结束语结束语结束语

用户头像

flfljh

关注

还未添加个人签名 2024-10-29 加入

还未添加个人简介

评论

发布
暂无评论
ohos开发flutter_module_flfljh_InfoQ写作社区