Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

鸿蒙add-to-app示例 #1993

Closed
0xZOne opened this issue Mar 23, 2024 · 4 comments
Closed

鸿蒙add-to-app示例 #1993

0xZOne opened this issue Mar 23, 2024 · 4 comments
Labels
OHOS Openharmony only

Comments

@0xZOne
Copy link
Collaborator

0xZOne commented Mar 23, 2024

一个简单的鸿蒙add-to-app示例:

https://github.com/0xZOne/ohos-flutter-add2app

@0xZOne 0xZOne added the OHOS Openharmony only label Mar 23, 2024
@0xZOne 0xZOne pinned this issue Mar 23, 2024
@0xZOne 0xZOne closed this as completed Mar 23, 2024
@wangqiaoguang
Copy link

能详细介绍下吗?我直接运行一致都没有成功,看不到flutter_boost.hap

@lingjianglin
Copy link

parse ohos project build data exception! Exception: can not found
module.json5 at
/Users/macbook/Documents/harmonyProject/ohos-flutter-add2app-main/my_flutte
r_module/.ohos/flutter_boost/src/main/module.json5 咋回事,能不能搞个 最新的文档,比如 flutter_boost 对应哪个分支 哪个commit ,鸿蒙的 flutter_flutter对应哪个分支,那个commit的详细一些 接入 你们flutter_boost的完整例子,现在这里一点,哪里一点,结构目录修改之后 ,又是一脸懵逼

@Huanxin1997
Copy link

必须使用 flutter_flutter 才能运行吗?是否使用官方flutter就无法兼容OHOS?

@joechan-cq
Copy link
Collaborator

joechan-cq commented Jul 4, 2024

编译运行鸿蒙版Flutter Boost Example

准备环境

Flutter SDK

必须使用OpenHarmony-Flutter(master或dev分支,基于官方3.7.12版本),官方的Flutter SDK,并不支持鸿蒙系统。使用Git将OpenHarmony-Flutterclone下来。如果开发环境中已经有了官方的Flutter版本,那么这里推荐使用FVM进行Flutter的版本管理。

FVM虽未在文档中说明,但其实是支持本地自定义的Flutter版本的。需要将下载的OpenHarmony-Flutter SDK放置于${fvm-dir}/versions目录下,并重命名为custom_3.7.12_ohos即可(必须以custom_为前缀)。使用fvm list命令可以确认是否已经将OpenHarmony-Flutter加入fvm管理。

FVM的使用方式见官方文档。

注意OpenHarmony-Flutter文档中所说的引擎编译产物已经不需要下载了,那些--local-engine,src/out什么的东西可以不用管。

鸿蒙开发工具

请从鸿蒙开发工具上下载Command Line ToolsDevEco Studio

环境变量配置

  • Flutter环境变量
export PUB_HOSTED_URL=https://pub.flutter-io.cn;
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  • 鸿蒙环境变量
export HOS_SDK_HOME=${ohos-cmd-tools-dir}/sdk
export PATH=$PATH:${ohos-cmd-tools-dir}/bin
export PATH=$PATH:${ohos-cmd-tools-dir}/tool/node/bin
export PATH=$PATH:${ohos-cmd-tools-dir}/sdk/HarmonyOS-NEXT-DB1/openharmony/toolchains

${ohos-cmd-tools-dir}为下载解压后的目录,自行替换。

环境验证

上述配置完成后,可以cd到OpenHarmony-Flutter文件夹的bin目录下,使用里面的flutter文件,进行校验:

./flutter doctor

[WARN] Not checking for version mismatch as custom version is being used.
[WARN] Version custom_3.7.12_ohos is not a valid semver
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel dev, 3.7.12-ohos, on macOS 13.6.5 22G621 darwin-arm64, locale zh-Hans-CN)
    ! Upstream repository https://gitee.com/openharmony-sig/flutter_flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to https://gitee.com/openharmony-sig/flutter_flutter.git to dismiss this error.

[✓] HarmonyOS toolchain - develop for HarmonyOS devices
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ! CocoaPods 1.10.1 out of date (1.11.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[!] Android Studio (version 2023.3)
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.91.0)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 4 categories.HarmonyOS toolchain`

检查HarmonyOS toolchain是否✓。

编译FlutterBoost

如果使用了fvm,需先使用fvm use custom_3.7.12_ohos命令,将项目依赖的SDK切换成鸿蒙Flutter。且后续使用fvm flutter命令代替flutter命令。

  1. 下载或Clone Flutter Boost 4.5.0或更新版本

  2. cd到example目录中,进行flutter pub getflutter pub upgrade

  3. 执行flutter build hap命令进行编译。编译成功,则会在example/ohos/entry/build/default/outputs/default目录中见到生成的未签名的hap文件。(如果安装了DevEco Studio,可直接在其中进行编译)

运行FlutterBoost

想要运行编译出来的hap,还需要进行签名。这里就直接推荐使用DevEco Studio,在Project StructureSigning Configs中勾选Automatically generate signature,然后直接在DevEco Studio中点击运行。

如果不想通过DevEco Studio进行签名和运行,则根据鸿蒙应用签名手动签名,然后使用hdc install <hap-file>命令安装hap文件。

调试FlutterBoost

想要在鸿蒙设备上调试Flutter程序,使用flutter attach命令,去绑定鸿蒙上的Flutter进程即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OHOS Openharmony only
Projects
None yet
Development

No branches or pull requests

5 participants