使用 Flutter SDK 3.22.1构建HarmonyOS应用
使用 Flutter SDK 3.22.1构建HarmonyOS应用
需要将
git clone https://gitee.com/openharmony-sig/flutter_flutter.git
更新为
git clone git@gitee.com:harmonycommando_flutter/flutter.git
然后打开~/.bash_profile配置文件,更改目录。
然后我们再去检查环境
jianguo@jianguodeMacBook-Pro-2 gitbook_flutter % flutter --version
Downloading Darwin arm64 Dart SDK from Flutter engine 5762f655aa9b45b309dfea9cd9a115a42f348dfe...
dart-sdk-url: https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com/flutter_infra_release/flutter/5762f655aa9b45b309dfea9cd9a115a42f348dfe/dart-sdk-darwin-arm64.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 84.3M 100 84.3M 0 0 33.6M 0 0:00:02 0:00:02 --:--:-- 33.7M
Building flutter tool...
Resolving dependencies...
Downloading packages... (1.5s)
Got dependencies.
Flutter 3.22.1-0.0.pre.6 • channel oh-3.22.0 • git@gitee.com:harmonycommando_flutter/flutter.git
Framework • revision 28138c9015 (19 hours ago) • 2024-11-04 07:41:35 +0000
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.1
现在我们就可以看到是3.22啦
项目配置
1.进入项目根目录,如果项目还未创建,则使用 flutter create
命令创建项目
flutter create my_app
assets chapter11 chapter15 chapter5 chapter9 styles
jianguo@jianguodeMacBook-Pro-2 gitbook_flutter % flutter create my_app
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Downloading Material fonts... 1,271ms
Downloading Gradle Wrapper... 28ms
Downloading package sky_engine... 635ms
Downloading flutter_patched_sdk tools... 301ms
Downloading flutter_patched_sdk_product tools... 152ms
Downloading darwin-arm64 tools... 909ms
Downloading libimobiledevice... 28ms
Downloading usbmuxd... 26ms
Downloading libplist... 27ms
Downloading openssl... 84ms
Downloading ios-deploy... 31ms
Downloading darwin-arm64/font-subset tools... 115ms
Developer identity "Apple Development: Shu Shu (669W3557MK)" selected for iOS code signing
Creating project my_app...
Resolving dependencies in `my_app`...
Downloading packages...
Got dependencies in `my_app`.
Wrote 161 files.
All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev
In order to run your application, type:
$ cd my_app
$ flutter run
Your application code is in my_app/lib/main.dart.
2.如果项目已经创建,还未添加鸿蒙平台支持,则使用以下命令添加鸿蒙平台支持。
flutter create --platforms ohos .
其中,.
代表当前目录。
目录结构类似如下所示
jianguo@jianguodeMacBook-Pro-2 my_app % tree -L 3
.
├── README.md
├── analysis_options.yaml
├── android
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── local.properties
│ ├── my_app_android.iml
│ └── settings.gradle
├── build
│ ├── 11ee55180268f2469c49c88e2119b930
│ │ ├── _composite.stamp
│ │ ├── gen_dart_plugin_registrant.stamp
│ │ └── gen_localizations.stamp
│ └── ohos
│ └── flutter_assets
├── ios
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ ├── Generated.xcconfig
│ │ ├── Release.xcconfig
│ │ └── flutter_export_environment.sh
│ ├── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── Base.lproj
│ │ ├── GeneratedPluginRegistrant.h
│ │ ├── GeneratedPluginRegistrant.m
│ │ ├── Info.plist
│ │ └── Runner-Bridging-Header.h
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ └── xcshareddata
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ └── RunnerTests
│ └── RunnerTests.swift
├── lib
│ └── main.dart
├── linux
│ ├── CMakeLists.txt
│ ├── flutter
│ │ ├── CMakeLists.txt
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ └── generated_plugins.cmake
│ ├── main.cc
│ ├── my_application.cc
│ └── my_application.h
├── macos
│ ├── Flutter
│ │ ├── Flutter-Debug.xcconfig
│ │ ├── Flutter-Release.xcconfig
│ │ ├── GeneratedPluginRegistrant.swift
│ │ └── ephemeral
│ ├── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── Base.lproj
│ │ ├── Configs
│ │ ├── DebugProfile.entitlements
│ │ ├── Info.plist
│ │ ├── MainFlutterWindow.swift
│ │ └── Release.entitlements
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ └── xcshareddata
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ └── RunnerTests
│ └── RunnerTests.swift
├── my_app.iml
├── ohos
│ ├── AppScope
│ │ ├── app.json5
│ │ └── resources
│ ├── build-profile.json5
│ ├── entry
│ │ ├── build
│ │ ├── build-profile.json5
│ │ ├── hvigorfile.ts
│ │ ├── oh-package.json5
│ │ └── src
│ ├── har
│ │ └── flutter.har
│ ├── hvigor
│ │ └── hvigor-config.json5
│ ├── hvigorfile.ts
│ ├── local.properties
│ ├── oh-package-lock.json5
│ ├── oh-package.json5
│ └── oh_modules
│ └── @ohos
├── pubspec.lock
├── pubspec.yaml
├── test
│ └── widget_test.dart
├── web
│ ├── favicon.png
│ ├── icons
│ │ ├── Icon-192.png
│ │ ├── Icon-512.png
│ │ ├── Icon-maskable-192.png
│ │ └── Icon-maskable-512.png
│ ├── index.html
│ └── manifest.json
└── windows
├── CMakeLists.txt
├── flutter
│ ├── CMakeLists.txt
│ ├── generated_plugin_registrant.cc
│ ├── generated_plugin_registrant.h
│ └── generated_plugins.cmake
└── runner
├── CMakeLists.txt
├── Runner.rc
├── flutter_window.cpp
├── flutter_window.h
├── main.cpp
├── resource.h
├── resources
├── runner.exe.manifest
├── utils.cpp
├── utils.h
├── win32_window.cpp
└── win32_window.h
54 directories, 84 files
创建命令执行成功后,项目中会出现 ohos
目录,这里面存放的就是鸿蒙平台的相关代码。
签名
1.在运行项目前,先对项目进行签名,否则在运行过程中会出现这样的错误
请通过DevEco Studio打开ohos工程后配置调试签名(File -> Project Structure -> Signing Configs 勾选Automatically generate signature)
2.用 DevEco 打开上面的 ohos
目录,注意不是项目目录,是项目下面的 ohos 鸿蒙目录,然后根据提示依次打开 File -> Project Structure -> Signing Configs
, 点击自动签名即可。
3.签名成功后,文件 ohos/build-profile.json5
会自动更新,里面的字段 signingConfigs
出现相应的签名配置信息。
运行
我们使用flutter run
等待就可。
这不是出来了,赞赞赞。
flutter run --debug -d 9CN0223901000559
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ The Google Privacy Policy describes how data is handled in this service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
║ ║
║ To disable animations in this tool, use ║
║ 'flutter config --no-cli-animations'. ║
╚════════════════════════════════════════════════════════════════════════════╝
Launching lib/main.dart on 9CN0223901000559 in debug mode...
start hap build...
Running Hvigor task assembleHap... 12.8s
✓ Built ohos/entry/build/default/outputs/default/entry-default-signed.hap.
installing hap. bundleName: com.example.my_app
坚果派
坚果派由坚果创建,团队拥有26个华为HDE,以及若干其他领域的三十余位万粉博主运营。专注于分享的技术包括HarmonyOS/OpenHarmony,ArkUI-X,元服务,服务卡片,华为自研语言,BlueOS操作系统、团队成员聚集在北京、上海、广州、深圳、南京、杭州、苏州、宁夏等地。 聚焦“鸿蒙原生应用”、“智能物联”和“AI赋能”、“人工智能”四大业务领域,依托华为开发者专家等强大的技术团队,以及涵盖需求、开发、测试、运维于一体的综合服务体系,赋能文旅、媒体、社交、家居、消费电子等行业客户,满足社区客户数字化升级转型的需求,帮助客户实现价值提升。 目前上架鸿蒙原生应用18款,三方库56个。
- 7回答
- 13粉丝
- 6关注
- 鸿蒙Flutter实战:11-使用 Flutter SDK 3.22.0
- 鸿蒙Flutter实战:06-使用ArkTs开发Flutter鸿蒙插件
- HarmonyOS应用开发实战:半天实现知乎日报项目( 五、组件导航Navigation使用详解)
- 鸿蒙Flutter实战:04-如何使用DevTools调试Webview
- 鸿蒙Flutter实战:12-使用模拟器开发调试
- HarmonyOS应用开发实战:半天实现知乎日报项目(九、知乎日报项目接口使用指南)
- [HarmonyOS] 鸿蒙中自定义SO库以及使用
- 鸿蒙Flutter实战:05-使用第三方插件
- HarmonyOS应用如何修改为OpenHarmony应用(API12)
- HarmonyOS应用程序访问控制探究
- HarmonyOS NEXT应用开发 ( 应用的签名打包上架,各种证书详解)
- 鸿蒙Flutter实战:13-鸿蒙应用打包上架流程
- # 最新 HUAWEI DevEco Studio 使用技巧
- Flutter鸿蒙入门
- Flutter鸿蒙实战