diff --git a/ohos/docs/08_FAQ/README.md b/ohos/docs/08_FAQ/README.md index 1cda50247a67b7065f75caac52164c79f81d8e0d..23aea6fc2f53244216bd69abb949042918a85fac 100644 --- a/ohos/docs/08_FAQ/README.md +++ b/ohos/docs/08_FAQ/README.md @@ -6,6 +6,8 @@ 2. [ohos引擎产物编译相关问题](./ohos_engine.md) 3. [ohos应用编译相关问题](./ohos_hap.md) 4. [ohos代码开发相关问题](./ohos_code.md) +5. [ohos运行相关问题](./ohos_run.md) +6. [功能开发相关问题](./04_development/README.md) ## flutter鸿蒙化应用相关问题反馈的关键信息模板 diff --git a/ohos/docs/08_FAQ/environment.md b/ohos/docs/08_FAQ/environment.md index 7cd500c3e72971929dcf5bc161eeef3ee38d73e5..7fcae016e70713dc7cd65e8d4c396583781a02c9 100644 --- a/ohos/docs/08_FAQ/environment.md +++ b/ohos/docs/08_FAQ/environment.md @@ -92,4 +92,22 @@ strict_ssl=false 解决方案:`rm ios/podfile && flutter clean && flutter run -d ` -参考链接:[GeneratedPluginRegistrant.m Module not found](https://github.com/flutter/flutter/issues/43986) \ No newline at end of file +参考链接:[GeneratedPluginRegistrant.m Module not found](https://github.com/flutter/flutter/issues/43986) + +## 【Windows】 flutter doctor -v 无反应 + +现象: 配置好环境变量后,执行flutter doctor -v没有反应 + +原因: 可能是没有配置好代理 + +解决: +- 在系统环境变量中配置http_proxy, https_proxy, no_proxy环境变量 +- http_proxy参考deveco代理配置 +- https_proxy可以等于http_proxy +- no_proxy参考deveco代理配置外,还需要添加 + - localhost + - ::1 + - 127.0.0.1 + +执行结果有Flutter和HarmonyOS(表明基础环境配置正确,这两个平台均被支持) +![](../media/08/error.png) diff --git a/ohos/docs/08_FAQ/ohos_code.md b/ohos/docs/08_FAQ/ohos_code.md index f569c2c248270f0e4f02699ce11521170235f4c4..09d32f94b72bb1142178457297ca4996e3b2daaa 100644 --- a/ohos/docs/08_FAQ/ohos_code.md +++ b/ohos/docs/08_FAQ/ohos_code.md @@ -8,4 +8,74 @@ import 'package:flutter/foundation.dart'; bool isOhos() { return defaultTargetPlatform == TargetPlatform.ohos; } -``` \ No newline at end of file +``` + + +## 代码中存在Platform.isOhos会导致fluttn run、flutter build har、flutter attach失败 +问题现象: +如果flutter代码中存在Platform.isOhos,如下: +``` +if (Platform.isAndroid || Platform.isOhos) { + print("test"); +} +``` +会导致flutter run、flutter build har、 flutter attach(不指定本地引擎产物,依赖服务器的引擎产物)失败, +报错信息: +![](../media/08/code1.png) + +解决方法: +请将 Platform.isOhos 修改成 defaultTargetPlatform == TargetPlatform.ohos + + +## flutter鸿蒙原生端获取到图片资源 +问:在使用plugin时, 鸿蒙会返回这个类型的对象binding: FlutterPluginBinding,使用这个对象的binding.getFlutterAssets().getAssetFilePathByName('xxxx') 获取flutter代码库中的图片资源时,鸿蒙原生端无法获取到图片资源(鸿蒙端直接用Image(this.img)方法加载)。有什么别的方法能够获取到? + +答:binding.getFlutterAssets().getAssetFilePathByName('xxxx')得到的是资源路径,加载原生图片资源可以参考以下实现 +![](../media/08/code2.png) +``` +import { image } from '@kit.ImageKit'; +@Component +export struct DemoComponent { + @Prop params: Params + viewManager: DemoView = this.params.platformView as DemoView + image?: string + @State imageSource:image.ImageSource|null=null + + async aboutToAppear() { + let args: HashMap = this.viewManager.args as HashMap + this.image = args.get('src') as string + let rmg = DemoPluginAssetPlugin.binding.getApplicationContext(). resourceManager; + let rawfile = await rmg.getRawFileContent("flutter_assets/${this.image}"); + let buffer = rawfile.buffer.slice(0); + this.imageSource = image.createImageSource(buffer); + } + + build() { + Column(){ + if(this.imageSource){ + Image(this.imageSource.createPixelMapSync()) + } + } + } + + // aboutToAppear(): void { + // let args: HashMap = this.viewManager.args as HashMap + // this.image = args.get('src') as string + // } + + // build() { + // //todo 问题点 + // // Image(this.image) + // Image(DemoPluginAssetPlugin.binding.getFlutterAssets().getAssetFilePathByName (this.image)) + // // Image(DemoPluginAssetPlugin.binding.getFlutterAssets(). getAssetFilePathBySubpath(this.image)) + // } +} +``` +问:let rawfile = await rmg.getRawFileContent("flutter_assets/"+this.image ); 这行代码会触发build方法么? 为什么我打断点打到这一行,然后继续执行断点直接就到build方法了? + +答:let rawfile = await rmg.getRawFileContent("flutter_assets/"+this.image );这行代码为耗时操作,debug时会暂不执行当前方法的剩余代码直到耗时操作返回结果,而进入build只是正常渲染流程 + +参考: +[demo](https://onebox.huawei.com/p/b3e5806b9ce3683c8c13b237ec319294) + +跑demo_plugin_asset\example\ohos可以跑起来界面,界面“flutter图片资源展示”下会显示图片,“原生图片资源展示”下未显示图片,相关代码在 demo_plugin_asset\example\lib\main.dart、demo_plugin_asset\ohos\src\main\ets\components\plugin\DemoPluginAssetPlugin.ets \ No newline at end of file diff --git a/ohos/docs/08_FAQ/ohos_hap.md b/ohos/docs/08_FAQ/ohos_hap.md index 8365569db2451948c3dfe48660997bcef212ca61..0222185f05c7f5ba03beb00cc14a7a0dab70e417 100644 --- a/ohos/docs/08_FAQ/ohos_hap.md +++ b/ohos/docs/08_FAQ/ohos_hap.md @@ -112,7 +112,20 @@ hvigor install success. ``` 问题分析:ohos工程的结构还是api11的,但是使用的sdk是api12的,这种情况下就会出现这个报错信息。 + 解决方案:将ohos工程结构升级为api12。 操作步骤: 1. DevEco-Studio -> Migrate Assistant -> 5.0.0 -> Migrate 2. DevEco-Studio -> File -> Project Structure -> Compatible SDK -> 5.0.0(12) + +## 通过flutter build hap -release 编译版本 会导致 app.json versionName 字段重置 +背景: +查看app.json 下的versionName 字段,然后执行flutter build hap -release 编译版本进行出包 + +现象:发现次字段 再次被重置1.0.0; + +原因:当前规格,目前默认build会使用这个版本号 + +解决:需要指定versionName和versionCode可以在build指令时加上指定版本 + +参考:flutter build hap --build-name=4.0.3 --build-number=10000 diff --git a/ohos/docs/08_FAQ/ohos_run.md b/ohos/docs/08_FAQ/ohos_run.md new file mode 100644 index 0000000000000000000000000000000000000000..d69e01db36f748ae5f959f19a310f90dcaf8e4b1 --- /dev/null +++ b/ohos/docs/08_FAQ/ohos_run.md @@ -0,0 +1,21 @@ +# ohos运行相关问题 + + +## 编译鸿蒙后运行出现运行时错误/data/storage/el1/bundle/entry/ets/modules.abc +问题现象:flutter编译鸿蒙后运行出现运行时错误 + +报错信息: +``` +com.wit.appzoo_flutter_v2 is about to exit due to RuntimeError +Error type:ReferenceError +Error name:ReferenceError +Error message:cannot find record 'pkg_modules/.ohpm/connectivity_plus@fhy6p0gmf3puymhvkbu4hxvnutt4mn48tk2kirtanmi=/pkg_modules/connectivity_plus/index', please check the request path.'/data/storage/el1/bundle/entry/ets/modules.abc'. +Stacktrace: +SourceMap is not initialized yet +#00 pc 00000000005fcc0c /system/lib64/platformsdk/libark_jsruntime.so(5144aa99644b9dba57555adfb9e0ede6) +#01 pc 00000000005fd128 /system/lib64/platformsdk/libark_jsruntime.so(5144aa99644b9dba57555adfb9e0ede6) +#02 pc 00000000002ac540 /system/lib64/platformsdk/libark_jsruntime.so(5144aa99644b9dba57555adfb9e0ede6) +``` +可能原因: +/data/storage/el1/bundle/entry/ets/modules.abc 可能是SDK与镜像不匹配导致abc文件无法正常运行,该现象根本原因是SDK工具与镜像版本不匹配,推荐使用匹配的SDK与手机镜像版本;请提供当前手机版本 和 ide版本截图。 +若版本是匹配的,请提供完整日志来。 diff --git a/ohos/docs/media/08/code1.png b/ohos/docs/media/08/code1.png new file mode 100644 index 0000000000000000000000000000000000000000..6416520af52eb15078ad32b70e9803590677b719 Binary files /dev/null and b/ohos/docs/media/08/code1.png differ diff --git a/ohos/docs/media/08/code2.png b/ohos/docs/media/08/code2.png new file mode 100644 index 0000000000000000000000000000000000000000..cf38a7c71b786fa1b7e7e7c36f6c2936c5d7701f Binary files /dev/null and b/ohos/docs/media/08/code2.png differ diff --git a/ohos/docs/media/08/error.png b/ohos/docs/media/08/error.png new file mode 100644 index 0000000000000000000000000000000000000000..10bf00fe88d8d640621f309f4c07614504af0303 Binary files /dev/null and b/ohos/docs/media/08/error.png differ