鸿蒙harmonyos next flutter混合开发之ohos工程引用 har 文件

  • 创建鸿蒙原生工程MyApplication。

  • 创建flutter module,生成har文件,并且将flutter module中.ohos文件entryability/EntryAbility.ets、pages/Index.ets分别替换MyApplication中的。

    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

  • 将上一步生成的har文件拷贝到原生工程中MyApplication/har/

    cp -r my_flutter_module/.ohos/har/* MyApplication/har/

  • 修改原生工程MyApplication/oh-package.json5,

    {
    "dependencies": {
    "@ohos/flutter_module": "./har/flutter_module.har",
    "@ohos/flutter_ohos": "file:./har/flutter.har"
    },
    "overrides": {
    "@ohos/flutter_ohos": "file:./har/flutter.har"
    }
    }

  • 对原生工程MyApplication进行签名

  • 运行 MyApplication

不知道为什么,这里app在模拟器中运行起来立马闪退。不知道是不是不支持模拟器运行,还是官方bug。运行日志如下,这里截取部分日志,也请知道原因的告知下,谢谢!

复制代码
Device info:emulator
Build info:emulator 5.0.0.65(SP73DEVC00E65R4P11log)
Fingerprint:f997680853fc6a9c5af3acd2878ed5936dc031867c36b8d1f7b42b8980fa8252
Module name:com.example.myapplication
Version:1.0.0
VersionCode:1000000
PreInstalled:No
Foreground:Yes
Timestamp:2024-10-01 20:34:34.447
Pid:17838
Uid:20020054
Process name:com.example.myapplication
Process life time:2s
Reason:Signal:SIGTRAP(TRAP_BRKPT)@0x0000007f96711dd0 
Fault thread info:
Tid:17879, Name:1.raster
#00 pc 00000000023d1dd0 /data/storage/el1/bundle/libs/arm64/libflutter.so(103fd5b90568edc09203e114faebbaedd8f359d3)

官方参考文档:ohos工程 引用 har 文件

相关推荐
时光慢煮1 小时前
打造跨端博客分类与标签组件:Flutter × OpenHarmony 实战
flutter·开源·openharmony
Easonmax6 小时前
零基础入门 React Native 鸿蒙跨平台开发:7——双向滚动表格实现
react native·react.js·harmonyos
Easonmax6 小时前
零基础入门 React Native 鸿蒙跨平台开发:6——竖向滚动表格实现
react native·react.js·harmonyos
Easonmax8 小时前
零基础入门 React Native 鸿蒙跨平台开发:8——固定表头和列的复杂表格
react native·react.js·harmonyos
zilikew10 小时前
Flutter框架跨平台鸿蒙开发——今日吃啥APP的开发流程
flutter·华为·harmonyos·鸿蒙
Whisper_Sy10 小时前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 应用列表实现
android·开发语言·javascript·flutter·php
数通工程师10 小时前
企业级硬件防火墙基础配置实战:从初始化到规则上线全流程
运维·网络·网络协议·tcp/ip·华为
BlackWolfSky10 小时前
鸿蒙中级课程笔记2—状态管理V2—@ObservedV2装饰器和@Trace装饰器:类属性变化观测
笔记·华为·harmonyos
血色橄榄枝10 小时前
03 基于Flutter集成网络请求On OpenHarmony
网络·flutter
小风呼呼吹儿11 小时前
Flutter 框架跨平台鸿蒙开发 - 虚拟拼豆图纸查看应用开发教程
flutter·华为·harmonyos