鸿蒙Flutter实战:10-常见问题集合

鸿蒙Flutter实战:10-常见问题集合

1. 学习路径应该是怎样的,需要掌握哪些技术才具备鸿蒙 Flutter 开发能力

1.1 学习和掌握 Flutter 开发技术,这块需要在Flutter社区学历 Flutter开发文档 1.2 学习鸿蒙基础概念和知识,推荐学习 鸿蒙生态应用开发白皮书, ArkTS 语言, ArkUI, HarmonyOS 第一课

2. MatePad 应用适配问题

如果出现 app 在 Matepad 上无法全屏的问题,需要在 ohos/entry/main/module.json5中配置设备类型:

json 复制代码
    "deviceTypes": [
      "phone",
      "tablet",
      "car",
      "2in1",
      'default'
    ],

需要增加 tablet 平板设备的适配。

如果在 Matepad 上运行时设备没有全屏,则可以需要删除 App 重装安装或者重启设备。因为相关的配置存在缓存,适配类型发生变化时,存在没有更新的问题,导致无法全屏。

3. 模拟器

模拟器与真机有较大差异,如果出现模拟器异常情况,优先确实真机是否正常运行,以排除模拟器自身问题。

4. debug 版本运行报错

Error while initializing the Dart VM

text 复制代码
依次执行以下操作
设置环境变量 export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com
删除 /bin/cache 目录下的缓存
执行 flutter clean,清除项目编译缓存
运行 flutter run -d $DEVICE --debug

5. 如何更换 App 图标和名称

找到 ohos/AppScope/resources/base/media/app_icon.png,替换相应的文件

找到 ohos/AppScope/resources/base/element/string.json 文件,修改以下配置

json 复制代码
{
  "string": [
    {
      "name": "app_name",
      "value": "中文名称"
    }
  ]
}

6. flutter run 运行 App 报错,提示命令找不到

bash 复制代码
Launching lib/main.dart on 127.0.0.1:5555
start hap build..-e ERROR: node: /Applications/DevEco-Studio.app/Contents/tools/ohpm/bin/ohpm: line 7: node: commandnot found
-e ERROR: NODE_HOME: /Applications/DevEco-Studio.app/Contents/tools/ohpm/bin/ohpm: line 11: /node:
o such file or directory
-e ERROR: NODE_HOME: /Applications/DevEco-Studio.app/Contents/tools/ohpm/bin/ohpm: line 25: /bin/noc
e: No such file or directory
-e ERROR: Failed to find the executable 'node' command, please check the following possible causes:e1. Node]s is not installed.e2.'node'command not added to PATH;
eand the 'NoDE HOME' variable is not set in the environment variables to match your NodeJsinstallation location.
ProcessException: The command failedCommand: ohpm clean

检查环境变量配置,配置成功后,检查是否已生效。通过 source ~/.zshrc 或重启命令行程序,甚至重启 IDE/系统,直至变量生效。

参考资料

【flutter鸿蒙技术交流群】

目前 Flutter 鸿蒙已经跑通,但仍然存在一些潜在的坑需要解决和处理,欢迎大家一起分享交流

请加小助手进群:

备注:鸿蒙Flutter

wx:zacksleo

相关推荐
Geek_Vison10 小时前
保险APP已经用了Flutter,还能接入小程序吗?
flutter·小程序·uni-app·mpaas·小程序容器
FungLeo10 小时前
成为全栈·Flutter App 篇·go_router 与四 Tab App Shell:保留导航状态、深链和登录回跳
flutter·移动开发·成为全栈·go_router·路由设计·深链接
m0_7381858211 小时前
Flutter 鸿蒙化实战:screen_protector 适配 OpenHarmony,防截屏/防泄露
flutter·华为·harmonyos·鸿蒙
梦想的颜色16 小时前
【编程实战】AI 时代 APP 开发全栈硬核指南:技术选型 + AI 架构 + 模型落地全维度决策
python·flutter·react native·react.js·ai·桌面应用·milvus
yuanlaile1 天前
2026年全新Flutter 跨平台开发全栈学习资料整理
flutter·getx·鸿蒙 next·flutter开发鸿蒙·flutter入门实战·flutter全栈
恋猫de小郭2 天前
Genkit Dart 1.0 发布,Flutter 原生的 AI Agent 终于完整了
android·前端·flutter
第10086个小白2 天前
flutter桌面端打包方式(Inno Setup Compiler)版本
前端·flutter
陆断枫3 天前
Flutter 3.47 动画引擎盘点:Impeller 全平台,和那些"新特性"
flutter
程序员老刘3 天前
Flet 1.0 思路很好,可惜来晚了
flutter·ai编程·客户端
m0_738185823 天前
Flutter 鸿蒙化实战:qr_code_scanner_plus 适配 OpenHarmony,二维码扫描
flutter·华为·harmonyos·鸿蒙