公司app是用纯flutter开发的,目前支持android和iOS,后续估计也会支持鸿蒙harmonyos。目前谷歌flutter并没有支持咱们国产手机操作系统鸿蒙harmonyos,于是乎国内有个叫OpenHarmony-SIG的组织,去做了鸿蒙harmonyos适配flutter开发的工作。本文就是基于OpenHarmony-SIG/flutter_flutter去搭建纯flutter开发环境。
- 鸿蒙开发环境搭建,鸿蒙开发套件官方下载地址如下:https://developer.huawei.com/consumer/cn/download/
- 下载鸿蒙版flutter
git clone -b dev https://gitee.com/openharmony-sig/flutter_flutter.git
- 下载FlutterEngine构建产物(非必选项),网盘下载地址Flutter Engine构建产物,FlutterEngine构建产物方便用来在android studio来运行、调试、打包等鸿蒙harmonyos项目flutter侧代码,当然你也可以通过DevEco-Studio来运行、调试、打包等鸿蒙代码。
flutter build hap [--local-engine=/Users/admin/Documents/flutter_engine/src/out/ohos_debug_unopt_arm64]
- 安装jdk,版本需为jdk 17,下载地址为Java Downloads | Oracle 中国
- 环境变量配置,注意:拉取下来的flutter_flutter/bin目录必须为第二步鸿蒙版flutter下载下来的bin目录。
export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # 拉取下来的flutter_flutter/bin目录 export PATH=/Users/administrator/Documents/flutter_flutter/bin:$PATH # jdk-17.jdk jdk-11.0.17.jdk zulu-8.jdk JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home PATH=$JAVA_HOME/bin:$PATH:. export JAVA_HOME export PATH # HamonyOS SDK export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # mac环境 export DEVECO_SDK_HOME=$TOOL_HOME/sdk # command-line-tools/sdk export PATH=$TOOL_HOME/tools/ohpm/bin:$PATH # command-line-tools/ohpm/bin export PATH=$TOOL_HOME/tools/hvigor/bin:$PATH # command-line-tools/hvigor/bin export PATH=$TOOL_HOME/tools/node/bin:$PATH # command-line-tools/tool/node/bin
- 检查环境,运行flutter doctor -v检查环境变量配置是否正确,Futter与OpenHarmony应都为ok
- 创建Flutter工程
# 创建工程 方式一 该方式只创建了ohos平台 flutter create --platforms ohos <projectName> # 创建工程 方式二 该方式创建了android,ios,ohos三个平台 flutter create <projectName> # 进入工程根目录编译hap包 flutter build hap --debug
- 鸿蒙真机运行Flutter项目
flutter run --debug -d <deviceId> flutter build hap --debug hdc -t <deviceId> install <hap file path>
- 当然我们也可以通过DevEco-Studio模拟器来运行flutter项目
参考文档:鸿蒙版Flutter环境搭建指导
标签:bin,鸿蒙,harmonyos,export,HOME,PATH,flutter From: https://blog.csdn.net/majun2009/article/details/142623439