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 文件
-
复制 har 文件
cp -r my_flutter_module/.ohos/har/* MyApplication/har/ -
修改 MyApplication/oh-package.json5
{
// ...
"dependencies": {
"flutter_module": "har/flutter_module.har"
},
"overrides": {
// 有冲突的依赖需要放到这里消除冲突
"@ohos/flutter_ohos": "har/flutter.har",
"plugin_xxx": "har/plugin_xxx.har"
}
} -
使用 Deveco Studio 配置 MyApplication 的签名
-
运行 MyApplication
方式二:ohos 工程 直接引用 flutter_module 源码 -
复制 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 -
修改 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"
]
}
]
}
]
} -
修改 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 -
使用 Deveco Studio 配置 MyApplication 的签名
-
运行 MyApplication