diff --git a/add_to_app/multiple_flutters/multiple_flutters_ohos/README.md b/add_to_app/multiple_flutters/multiple_flutters_ohos/README.md index 6c086c67e32940df34aad7fe53833436db55d8c2..e6716b5c955dc1120e9baf75abb3da61b1ed0b5e 100644 --- a/add_to_app/multiple_flutters/multiple_flutters_ohos/README.md +++ b/add_to_app/multiple_flutters/multiple_flutters_ohos/README.md @@ -10,9 +10,7 @@ cd ../multiple_flutters_module flutter pub get flutter build har --local-engine=$ENGINE_DEBUG --debug cd - -cp ../multiple_flutters_module/.ohos/flutter_module/har/flutter.har ./har/flutter.har -cp ../multiple_flutters_module/.ohos/flutter_module/har/url_launcher_ohos.har ./har/url_launcher_ohos.har -cp ../multiple_flutters_module/.ohos/flutter_module/build/default/outputs/default/flutter_module.har ./har/flutter_module.har +cp -r ../multiple_flutters_module/.ohos/flutter_module/har/* ./har/ open -a "Deveco-Studio" ../multiple_flutters_ohos/ # macOS command # Config signing configs: (File->Project Structure->Signing Configs->Support HarmonyOS & Automaticlally generate signature->OK) # (build and run) diff --git "a/ohos/docs/04_development/\345\246\202\344\275\225\344\275\277\347\224\250PlatformView.md" "b/ohos/docs/04_development/\345\246\202\344\275\225\344\275\277\347\224\250PlatformView.md" index 8ca2fd77541607906506641fc1ffbd0a1f1a94a1..a80593e7a2fa6179aff62a91aff444979502fa88 100644 --- "a/ohos/docs/04_development/\345\246\202\344\275\225\344\275\277\347\224\250PlatformView.md" +++ "b/ohos/docs/04_development/\345\246\202\344\275\225\344\275\277\347\224\250PlatformView.md" @@ -23,7 +23,7 @@ 3. 新建`CustomView.ets`文件,`CustomView`用于在Flutter Widget里显示 3.1 定义一个`Component`,代表ohos的`PlatformView`的定义 -```java +```ts @Component struct ButtonComponent { @Prop params: Params @@ -59,7 +59,7 @@ struct ButtonComponent { ``` 3.2 定义一个builder方法,放入3.1的自定义Component组件 -```java +```ts @Builder function ButtonBuilder(params: Params) { ButtonComponent({ params: params }) @@ -68,7 +68,7 @@ function ButtonBuilder(params: Params) { ``` 3.3 继承PlatformView实现一个自定义的Customview,实现getView接口,返回`WrappedBuilder(ButtonBuilder)`,放入3.2的builder方法 -```java +```ts import MethodChannel, { MethodCallHandler, MethodResult @@ -126,7 +126,7 @@ export class CustomView extends PlatformView implements MethodCallHandler { 4. 实现一个自定义的`PlatformViewFactory`,在其`create`方法中创建自定义的`PlatformView`的实例 -```java +```ts import common from '@ohos.app.ability.common'; import MessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/MessageCodec'; import PlatformViewFactory from '@ohos/flutter_ohos/src/main/ets/plugin/platform/PlatformViewFactory'; @@ -150,7 +150,7 @@ export class CustomFactory extends PlatformViewFactory { 5. 实现一个`FlutterPlugin`插件,在`onAttachedToEngine`中,注册自定义的`PlatformViewFactory` -```java +```ts import { FlutterPlugin, FlutterPluginBinding } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec'; @@ -172,7 +172,7 @@ export class CustomPlugin implements FlutterPlugin { 6. 打开`EntryAbility.ets`文件,添加Plugin(也可以把自定义PlatformView写在一个鸿蒙插件中,在应用中沿用,就不用在此显式添加插件) -```java +```ts import { FlutterAbility } from '@ohos/flutter_ohos' import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; import { CustomPlugin } from '../CustomPlugin'; @@ -308,6 +308,8 @@ OhosView组件就是桥接PlatformView的关键。 5、实现`CustomOhosView`,使用`OhosView`组件,`viewType`需要和ets侧`FlutterPlugin`做`registerViewFactory`操作时指定的`viewType`一致 ```dart +typedef OnViewCreated = Function(CustomViewController); + class CustomOhosView extends StatefulWidget { final OnViewCreated onViewCreated; diff --git "a/ohos/docs/04_development/\345\274\200\345\217\221module.md" "b/ohos/docs/04_development/\345\274\200\345\217\221module.md" index bf4f7e3656da81e242ac26e4314bc4cd0c1678a3..5378e59e606a86b683ed0b56e925dbff8adff856 100644 --- "a/ohos/docs/04_development/\345\274\200\345\217\221module.md" +++ "b/ohos/docs/04_development/\345\274\200\345\217\221module.md" @@ -44,41 +44,29 @@ cp -r my_flutter_module/.ohos/har/* MyApplication/har/ { // ... "dependencies": { - "@ohos/flutter_ohos": "./har/flutter.har" + "flutter_module": "har/flutter_module.har" }, "overrides": { - "@ohos/flutter_ohos": "./har/flutter.har" // 有冲突的依赖需要放到这里消除冲突 + "@ohos/flutter_ohos": "har/flutter.har", + "plugin_xxx": "har/plugin_xxx.har" } } ``` -#### 2. 修改 MyApplication/entry/oh-package.json5 - -```json -{ - // ... - "dependencies": { - "@ohos/flutter_module": "../har/flutter_module.har", - // 如果有其他引用,也需要依赖,例如:flutter_webview_ohos - "flutter_webview_ohos": "../har/flutter_webview_ohos.har" - } -} -``` - -注意:在代码中 - #### 3. 使用 Deveco Studio 配置 MyApplication 的签名 #### 4. 运行 MyApplication ### 方式二:ohos工程 直接引用 flutter_module 源码 -#### 1. 复制 flutter_module 源码 和 flutter.har +#### 1. 复制 flutter_module 源码 和 flutter相关文件 ```sh cp -r my_flutter_module/.ohos/flutter_module MyApplication/ -cp my_flutter_module/.ohos/ohos/flutter.har MyApplication/har/flutter.har +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 ``` #### 2. 修改 MyApplication/build-profile.json5 @@ -116,13 +104,17 @@ cp my_flutter_module/.ohos/ohos/flutter.har MyApplication/har/flutter.har } ``` -#### 3. 修改 MyApplication/entry/oh-package.json5 +#### 3. 修改 MyApplication/oh-package.json5 ```json { // ... "dependencies": { - "@ohos/flutter_module": "../flutter_module" + "flutter_module": "./flutter_module", + "@ohos/flutter_ohos": "./har/flutter.har" + }, + "overrides": { + "@ohos/flutter_ohos": "./har/flutter.har" } } ``` diff --git a/ohos/docs/08_FAQ/README.md b/ohos/docs/08_FAQ/README.md index b335ed20d66e242cfae0fee6367f4049eab020ac..18a39053aad4b3838dac2c706d2000315faccf81 100644 --- a/ohos/docs/08_FAQ/README.md +++ b/ohos/docs/08_FAQ/README.md @@ -6,3 +6,30 @@ 2. [ohos引擎产物编译相关问题](./ohos_engine.md) 3. [ohos应用编译相关问题](./ohos_hap.md) 4. [ohos代码开发相关问题](./ohos_code.md) + +## flutter鸿蒙化应用相关问题反馈的关键信息模板 + +1. IDE版本号,例如 + 1. DevEco-Studio 5.0.3.300 +2. 鸿蒙手机或模拟器的设备名称和系统版本号,可在 "设置->关于手机" 中查看,例如 + 1. HUAWEI Mate 60 Pro, 3.0.0.22(SP81xxxxxx) + 2. emulator, 3.0.0.22(SP39xxxxxx) +3. flutter运行环境检测信息,例如 + 1. `flutter docotr -v` +4. flutter编译或运行命令,例如 + 1. `flutter build hap --debug` + 2. `flutter run -d $DEVICE --debug` +5. 日志文件 + 1. 编译或运行日志,例如 + 1. `flutter build hap --debug 2>&1 | tee build.log` + 2. `flutter run -d $DEVICE --debug 2>&1 | tee run.log` + 2. hilog日志文件 + 1. 可通过命令导出到文件 `hdc hilog 2>&1 | tee hilog.log` + 1. windows 环境可以在 "Git Bash" 窗口中运行这个命令。 + 2. `hdc` 工具在 HamonyOS SDK 中的 toolchains 目录下 + 3. 闪退日志文件 + 1. 可在DevEco-Studio中获取, "DevEco-Studio -> Log -> FaultLog -> 应用包名 -> cppcrash/jscrash -> 时间点 -> 鼠标右键导出日志文件" + +## --local-engine 参数 + +flutter_flutter 在 ecd66426679c18f86a285a1ac6aa605900dcb63a (2024-06-06 20:00:49 GMT+0800) 之后的版本,`--local-engine` 成为了可选参数,可以不传。 \ No newline at end of file