ohos 开发 flutter_module

1.DevEco-Studio 搭建原生工程
使用 flutter_flutter,配置相关的环境变量

使用 flutter_engine 生成的engine产物

2.搭建 flutter_module 工程

1. 创建 flutter子模块工程

flutter create -t module my_flutter_module

2. 编译生成 flutter_module.har

cd my_flutter_module
flutter build har --debug
cd -

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.ets
cp 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 源码

  5. 复制 flutter_module 源码 和 flutter 相关文件
    cp -r my_flutter_module/.ohos/flutter_module MyApplication/
    mkdir -p MyApplication/flutter_module/src/main/resources/rawfile
    cp -r my_flutter_module/.ohos/flutter_module/src/main/resources/rawfile/flutter_assets MyApplication/flutter_module/src/main/resources/rawfile
    cp my_flutter_module/.ohos/har/flutter.har MyApplication/har/flutter.har
    cyhh.51yjjy.com,cyhh.testoppo.com,cyhh.huaxinlighting.com
    cyhh.51jyo.com,cyhh.bctiantuo.com

  6. 修改 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"
    ]
    }
    ]
    }
    ]
    }

  7. 修改 MyApplication/oh-package.json5
    {
    // ...
    "dependencies": {
    "flutter_module": "./flutter_module",
    "@ohos/flutter_ohos": "./har/flutter.har"
    },
    "overrides": {
    "@ohos/flutter_ohos": "./har/flutter.har"
    }
    }
    cyhh.yjh9988.com,cyhh.jyh01.com,cyhh.gzysart.com
    cyhh.kfamaw.com,cyhh.shplcchina.com

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

  9. 运行 MyApplication

posted @   个人问过  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
点击右上角即可分享
微信分享提示