flutter_flutter:基于 Flutter 技术栈的 OpenHarmony 应用开发工具项目

开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,复用现有 Flutter 生态资源。该项目是 Flutter SDK 的 OpenHarmony 适配版本,基于 Flutter 官方 3.27.4 版本构建,支持创建、构建、运行等多种开发指令。【此简介由AI生成】

分支46Tags55
文件最后提交记录最后更新时间
chore: update pull request description template Signed-off-by: gaoyu321 <2376518379@qq.com> 1 个月前
Adjust repo config for VS Code formatting (#122758) If someone's user settings include the following, the current workspace level formatting settings don't apply since they aren't as specific. ``` "[dart]": { "editor.formatOnSave": true, "editor.formatOnType": true, } ``` This PR handles this by turning off auto-formatting specifically for Dart files. This PR also adds "files.trimTrailingWhitespace": true to simplify [contribution guide](https://github.com/flutter/flutter/wiki/Setting-up-the-Framework-development-environment#set-up-your-environment). Fixes https://github.com/flutter/flutter/issues/122050. This change is test-exempt. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with ///). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing.3 年前
更新版权头信息 Signed-off-by: chenzhensheng79 <15118029047@139.com> 1 年前
Branch oh-3.27.4-dev update engine.ohos.har.version to e89c068aa50c1b13f077f467703a009fd441b4aa Signed-off-by: gaoyu321 <2376518379@qq.com> 4 个月前
add git config Co-authored-by: 谢代荣<xiedairong@huawei.com> 4 个月前
oh-3.27.4-dev分支回退模版和测试工程api版本为api12 Signed-off-by: liujiake <liujiake999@163.com> 9 个月前
更新文档 Signed-off-by: wenwenyang <707997111@qq.com> 1 个月前
Merge commit 'a241f514edfb61ca721a0ffdbd4de05bd82e007f' into oh-3.27.4-dev 1 年前
修改Column溢出到Column溢出切换,缩放值不准确问题 Signed-off-by: quanhonghui <quanhonghui@foxmail.com> 4 个月前
添加3.27.4-ohos-1.0.1版本ReleaseNote Signed-off-by: g60090854 <gaoweiheng1@h-partners.com> 6 个月前
Merge commit 'a241f514edfb61ca721a0ffdbd4de05bd82e007f' into oh-3.27.4-dev 1 年前
Add pre-stable support for create on Windows (#51895) Adds initial support for flutter create of apps and plugins. This is derived from the current FDE example app and sample plugin, adding template values where relevant. Since the APIs/tooling/template aren't stable yet, the app template includes a version marker, which will be updated each time there's a breaking change. The build now checks that the template version matches the version known by that version of the tool, and gives a specific error message when there's a mismatch, which improves over the current breaking change experience of hitting whatever build failure the breaking change causes and having to figure out that the problem is that the runner is out of date. It also adds a warning to the create output about the fact that it won't be stable. Plugins don't currently have a version marker since in practice this is not a significant problem for plugins yet the way it is for runners; we can add it later if that changes. Fixes #307046 年前
Clean up .gitignore files (#153060) This removes some unnecessary .gitignore files that are already covered by the top-level .gitignore file. This ensures that flutter running examples in this repo doesn't result in modifications by the new Swift Package Manager migration. Follow up to https://github.com/flutter/flutter/pull/152766 Part of https://github.com/flutter/flutter/issues/1480181 年前
Fix ZoomPageTransitionsBuilder hardcoded fill color (#154057) Fixes: #115275 Fixes: #116127 Fixes: #126682 Continuing on: #139078 (Credits to @LowLevelSubmarine for his initial work!) When using ZoomPageTransitionsBuilder, which is the default for ThemeData with a MaterialApp, dark edges would show around the exiting page that was being zoomed out in the background. Other times, a scrim (what looked like a slightly transparent dark overlay over the page) would appear. After some experimenting it was concluded that, in the first case, this was because both pages don't fully fill the enclosing scaffold area during the transition and the color for filling the remaining space was set hard coded as Colors.black. The second case (scrim) happens when navigating from a page with an enclosing scaffold to a nested one, without a scaffold, unlike the first case that happens when both pages have a (different) enclosing scaffold, except this time it would be the hard coded color covering the page with a slight opacity reduction. ### Changes - Replaced the hard coded color for transition filling with the current ThemeData.colorScheme.surface - Added a RenderBox based test to verify the correct color is being used in the transition. ## Preview **Before, notice the dark outline flash when navigating to the first page and the scrim when navigating to the second:** https://github.com/user-attachments/assets/b4cc8658-1008-49f4-8553-abd5fcc72989 **After, using the theme relative color (in this case the default white) to replace the hard coded value:** https://github.com/user-attachments/assets/b70f42d2-6246-4964-99d1-34ff8051ab06 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation. - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md1 年前
[flutter_releases] Flutter stable 3.27.0 Framework Cherrypicks (#162538) # Flutter stable 3.27.0 Framework ## Scheduled Cherrypicks https://github.com/flutter/flutter/pull/1621321 年前
添加3.27.4-ohos-1.0.1版本ReleaseNote Signed-off-by: g60090854 <gaoweiheng1@h-partners.com> 6 个月前
remove fujino from CODEOWNERS (#155369) Every time someone tries to merge stable into master, I get pinged. It's not worth the distraction. I initially added myself as CODEOWNER because I wanted to make sure people weren't adding unneccessary dependencies to the tool, but I give up.1 年前
Update old wiki links (#149544) Part of https://github.com/flutter/flutter/issues/145009 Finishes updating links in the repo that pointed to the old wiki1 年前
Misc docs cleanup and fixes (#155501) 1 年前
License update (#45373) * Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs 6 年前
更新版权头信息 Signed-off-by: chenzhensheng79 <15118029047@139.com> 1 年前
更新版权头信息 Signed-off-by: chenzhensheng79 <15118029047@139.com> 1 年前
Rename patent file (#38686) Rename this file to work around a limitation of the GitHub license detection tool, to ensure the repo is correctly tagged as BSD licensed6 年前
Adaptation of Flutter 3.22 for the OHOS platform 1 年前
flutter3.27.4鸿蒙化适配,修改文档和编译运行问题 Signed-off-by: hezhengyi <ssyzesb@qq.com> 1 年前
更新文档 Signed-off-by: wenwenyang <707997111@qq.com> 1 个月前
更新文档 Signed-off-by: wenwenyang <707997111@qq.com> 1 个月前
[CP-beta]Support host android apps with kts gradle files for add to app (#157881) This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? This allows host Android apps using Kotlin Gradle files to depend on a Flutter module as source, see https://docs.flutter.dev/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency. Previously they wouldn't be able to, because we expected the host app to use setBinding in it's Gradle files, which is Groovy syntax that doesn't have a parallel in the Kotlin Gradle DSL. They could still depend on a flutter module if built as an aar. ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples Allows host Android apps using Kotlin Gradle files to include a Flutter module. ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) Without this change, Android apps using Kotlin Gradle files are unable to depend on a Flutter module as source (they would still be able to as an aar). ### Workaround: Is there a workaround for this issue? Build the flutter module as an aar. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: What are the steps to validate that this fix works? Create a new Android app (probably in Android studio). Create a Flutter module (flutter create foobar --template=module). Apply [this diff](https://github.com/flutter/flutter/commit/1f1e92ac79403745d609220ce74c09a446eb4e6c), matching names to your specific case, to the Android app.1 年前
fix some unintended HTML tags in docs (#153507) I used the unintended_html_in_doc_comment to find these, but sadly the lint is not ready to be enabled yet due to https://github.com/dart-lang/linter/issues/5065.1 年前
Move snippets package back into flutter repo (#147690) ## Description This moves the snippets package back into the Flutter repo so that API documentation generation can happen without the use of dart pub global run because pub run doesn't handle concurrency well. The change modifies the dartdoc building process to include building an executable from the snippets tool and installing that in the cache directory for use during docs generation. The snippets tool will reside in dev/snippets, where it originally resided before being moved to https://github.com/flutter/assets-for-api-docs. The snippets code itself is unchanged from the code that is in https://github.com/flutter/assets-for-api-docs/packages/snippets. ## Related Issues - https://github.com/flutter/flutter/issues/144408 - https://github.com/flutter/flutter/issues/147609 - https://github.com/flutter/flutter/pull/147645 ## Tests - Added snippets tests to the overall testing build.2 年前
License update (#45373) * Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs 6 年前

Flutter SDK 仓库

仓库说明

本仓库是 Flutter SDKOpenHarmony 适配版本,由 OpenHarmony-Flutter 团队维护。开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,复用现有 Flutter 生态资源。

该版本分支基于 Flutter 官方社区 3.27.4 版本构建。

版本规划与分支策略请参见:Flutter OH 版本规划与分支策略

开发指南

升级指导

请参见:Flutter OH 版本升级指导

支持指令

已适配 OpenHarmony 开发的指令列表:

指令名称 指令描述 使用说明
doctor 环境检测 flutter doctor
config 环境配置 flutter config --<key> <value>
create 创建新项目 flutter create --platforms [ohos,android,ios] --org <org> <appName>
create 创建module模板 flutter create -t module <module_name>
create 创建plugin模板 flutter create -t plugin --platforms [ohos,android,ios] <plugin_name>
create 创建plugin_ffi模板 flutter create -t plugin_ffi --platforms [ohos,android,ios] <plugin_name>
devices 已连接设备查找 flutter devices
install 应用安装 flutter install -t <deviceId> <hap文件路径>
assemble 资源打包 flutter assemble
build 测试应用构建 flutter build hap --debug [--target-platform ohos-arm64] [--local-engine=<兼容ohos的debug engine产物路径>]
build 正式应用构建 flutter build hap --release [--target-platform ohos-arm64] [--local-engine=<兼容ohos的release engine产物路径>]
run 应用运行 flutter run [--local-engine=<兼容ohos的engine产物路径>]
attach 调试模式 flutter attach
screenshot 截屏 flutter screenshot
pub 获取依赖 flutter pub get
clean 清除项目依赖 flutter clean
cache 清除全局缓存数据 flutter pub cache clean

常见问题

  1. 切换FLUTTER_STORAGE_BASE_URL后需删除<flutter>/bin/cache 目录,并在项目中执行flutter clean后再运行

  2. 若出现报错:The SDK license agreement is not accepted,参考执行以下命令后再次编译:

    ./ohsdkmgr install ets:9 js:9 native:9 previewer:9 toolchains:9 --sdk-directory='/home/xc/code/sdk/ohos-sdk/' --accept-license
    
  3. 如果你使用的是DevEco Studio的Beta版本,编译工程时遇到"must have required property 'compatibleSdkVersion', location: demo/ohos/build-profile.json5:17:11"错误,请参考**《DevEco Studio配置文件》**中的 工程级build-profile.json5文件 → products 配置 compatibleSdkVersion

  4. 若提示安装报错:fail to verify pkcs7 file 请执行指令

    hdc shell param set persist.bms.ohCert.verify true
    
  5. linux虚拟机通过hdc无法直接发现OpenHarmony设备

    解决方案:在windows宿主机中,开启hdc server,具体指令如下:

    hdc kill
    hdc -s serverIP:8710 -m
    

    在linux中配置环境变量:

    HDC_SERVER=<serverIP>
    HDC_SERVER_PORT=8710
    

    配置完成后flutter sdk可以通过hdc server完成设备连接,也可参考官方指导

  6. 构建Hap任务时报错:Error: The hvigor depends on the npmrc file. Configure the npmrc file first.

    请在用户目录~下创建文件.npmrc,该配置也可参考DevEco Studio官方文档,编辑内容如下:

    registry=https://repo.huaweicloud.com/repository/npm/
    @ohos:registry=https://repo.harmonyos.com/npm/
    
  7. 查日志时,存在日志丢失现象。 解决方案:关闭全局日志,只打开自己领域的日志

    # 步骤一:关闭所有领域的日志打印(部分特殊日志无法关闭)
    hdc shell hilog -b X
    # 步骤二:只打开自己领域的日志
    hdc shell hilog <level> -D <domain>
    # 其中<level>为日志打印的级别:D/I/W/E/F,<domain>为Tag前面的数字
    # 举例:
    # 打印A00000/XComFlutterOHOS_Native的日志,需要设置hdc shell hilog -b D -D A00000
    # 注:上面的设置在机器重启后会失效,如果要继续使用,需要重新设置。
    
  8. 若Api11 Beta1版本的机器上无法启动debug签名的应用,可以通过将签名换成正式签名,或在手机端打开开发者模式解决(步骤:设置->通用->开发者模式)

  9. 如果报Invalid CEN header (invalid zip64 extra data field size)异常,请更换Jdk版本,参见JDK-8313765

  10. 运行debug版本的flutter应用用到鸿蒙设备后报错(release和profile版本正常)

    1. 报错信息: Error while initializing the Dart VM: Wrong full snapshot version, expected '8af474944053df1f0a3be6e6165fa7cf' found 'adb4292f3ec25074ca70abcd2d5c7251'
    2. 解决方案: 依次执行以下操作
      1. 设置环境变量 export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com
      2. 删除 /bin/cache 目录下的缓存
      3. 执行 flutter clean,清除项目编译缓存
      4. 运行 flutter run -d $DEVICE --debug
    3. 补充信息: 运行android或ios出现类似错误,也可以尝试还原环境变量 FLUTTER_STORAGE_BASE_URL ,清除缓存后重新运行。
  11. Beta2版本的ROM更新后,不再支持申请有执行权限的匿名内存,导致debug运行闪退。

    1. 解决方案:更新 flutter_flutter 到 a44b8a6d (2024-07-25) 之后的版本。

    2. 关键日志:

          #20 at attachToNative (oh_modules/.ohpm/@ohos+flutter_ohos@g8zhdaqwu8gotysbmqcstpfpcpy=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterNapi.ets:78:32)
          #21 at attachToNapi (oh_modules/.ohpm/@ohos+flutter_ohos@g8zhdaqwu8gotysbmqcstpfpcpy=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine.ets:144:5)
          #22 at init (oh_modules/.ohpm/@ohos+flutter_ohos@g8zhdaqwu8gotysbmqcstpfpcpy=/oh_modules/@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine.ets:133:7)
      
  12. 构建Hap命令直接执行flutter build hap即可,不再需要--local-engine参数,直接从云端获取编译产物。

  13. 配置环境完成后执行 flutter 命令 出现闪退。

    1. 解决方案:windows环境中添加git环境变量配置。

      export PATH=<git path>/cmd:$PATH
      
  14. 执行flutter pub cache clean 正常 执行flutter clean 报错,按照报错信息执行 update 命令也没有效果。

    1. 解决方案:通过注释掉 build.json5 文件中的配置规避。

    2. 报错信息:

       #Parse ohos module. json5 error: Exception: Can not found module.json5 at
       #D:\pub_cache\git\flutter_packages-b00939bb44d018f0710d1b080d91dcf4c34ed06\packages\video_player\video_player_ohos\ohossrc\main\module.json5.
       #You need to update the Flutter plugin project structure.
       #See
       #https://gitcode.com/openharmony-tpc/flutter_samples/blob/master/ohos/docs/09_specifications/update-flutter-plugin-structure.md
      
  15. 执行flutter build hap 时遇到路径校验报错。

    1. 解决方案: ·打开 deveco 安装路径 D:\DevEco Studio\tools\hvigor\hvigor-ohos-plugin\res\schemas 下的 ohos-project-build-profile-schema.json文件。 ·在该文件中找到包含:"pattern": "^(\./|\.\./)[\s\S]+$"的行,并删除此行。

    2. 报错信息:

       #hvigor  ERROR: Schema validate failed.
       #        Detail: Please check the following fields.
       #instancePath: 'modules[1].scrPath',
       #keyword: 'pattern'
       #params: { pattern:'^(\\./|\\.\\./)[\\s\\S]+$' },
       #message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
       #location: 'D:/work/videoplayerdemo/video_cannot_stop_at_background/ohos/build-profile.json:42:146'
      
  16. 执行flutter build hap 报错。

    1. 解决方案:打开 deveco 安装路径 D:\DevEco Studio\tools\hvigor\hvigor-ohos-plugin\src\model\module 下的 core-module-model-impl.js, 修改 findBelongProjectPath 方法(需要管理员权限,可另存为后替换)

       findBelongProjectPath(e) {
         if (e === path_1.default.dirname(e)) {
            return this.parentProject.getProjectDir()
         }
       }
      
    2. 报错信息:

      # hvigor  ERROR: Cannot find belonging project path for module at D:\.
      # hvigor  ERROR:  BUILD FAILED in 2s 556ms.
      #Running Hvigor task assembleHap...
      #Oops; flutter has exited unexpectedly: "ProcessException: The command failed
      #  <Command: hvigorw --mode module -p module=video_player_ohos@default -p product=default assmbleHar --no-daemon"
      #A crash report has been written to D:\work\videoplayerdemo\video_cannot_stop_at_background\flutter_03.log.
      
  17. DevEco-Studio(5.0.3.600 Beta3),windows版本编译flutter应用报错

    1. 解决方案:更新 flutter_flutter 到 c6fbac2b (2024-08-09) 之后的版本。

    2. 关键日志:

      hvigor ERROR: Schema validate failed.
      	Detail: Please check the following fields.
      	{
      		instancePath: 'modules[2].srcPath',
      		keyword: 'pattern',
      		params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
      		message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
      	}
      
  18. 在.ohos的项目执行flutter clean 报错,然后再执行flutter pub get也报错。

    1. 解决方案:删除.ohos文件夹,重新flutter pub get 即可

    2. 报错信息:

         Oops; flutter has exited unexpectedly: "PathNotFoundException: Cannot open file, path = 'D:\code\.ohos\build-profile.json5' (OS Error: 系统找不到指定的文件。,error = 2)".
         A crash report has been written to D:\code\flutter_01.log.
      
  19. 模拟器执行时发生白屏、崩溃等现象。

    1. 模拟器只支持Mac(arm64), 还不支持Mac(x86)和Windows
    2. 模拟器暂不支持vulkan,请尝试构建步骤2.1,关闭impeller后重试
  20. flutter profile模式下编译或运行失败

    1. 请在ohos项目build_profile.json5中添加buildModeSet字段,可参考complex_layout

    2. 报错信息:

      hvigor ERROR: Build mode 'profile' used in command line is not declared in buildModeSet in /xxx/example/ohos/build-profile.json5.
      

更多FAQ

贡献指南

如果您想为 Flutter-OH 贡献代码,请参考 Flutter-OH 代码合入流程 了解详细的贡献步骤和规范。

问题交流

项目介绍

开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,复用现有 Flutter 生态资源。该项目是 Flutter SDK 的 OpenHarmony 适配版本,基于 Flutter 官方 3.27.4 版本构建,支持创建、构建、运行等多种开发指令。【此简介由AI生成】

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新

语言类型

Dart98.63%
C++0.23%
Objective-C0.15%
CMake0.14%
Java0.14%