diff --git a/README.en.md b/README.en.md index 87a9d2cc923b2aa88152fbdd9852c42df45ad910..114ad9ac675a27b547426601528f9a3f0cdc022d 100644 --- a/README.en.md +++ b/README.en.md @@ -6,61 +6,71 @@ Original warehouse source: https://github.com/flutter/flutter ## Warehouse description This repository is a compatible extension of Flutter SDK for the OpenHarmony platform, and can support IDE or terminal use of Flutter Tools instructions to compile and build OpenHarmony applications. +## Development document +[Docs](https://gitee.com/openharmony-sig/flutter_samples/tree/master/ohos/docs) + ## Environment dependencies * development system Flutter Tools commands are currently supported on Linux, Mac and Windows. +* development limitations + + The Flutter project and dependent plugin projects in the Windows environment need to be on the same disk. + * Environment configuration - **Please give priority to downloading the supporting development tools from [Hongmeng Kit List](https://developer.harmonyos.com/deveco-developer-suite/enabling/kit?currentPage=1&pageSize=100). Downloads from other channels are not currently supported. Kit** + **Please download the supporting development tool from [OpenHarmony SDK](https://developer.huawei.com/consumer/cn/develop)** *The following environment variable configuration is for Unix-like systems (Linux, Mac). You can directly refer to the configuration below. For environment variable configuration under Windows, please set it in ‘Edit System Environment Variables’* - 1. Download OpenHarmony SDK and configure environment variables - * API12, deveco-studio-5.0.3.300 or command-line-tools-5.0.3.300 + 1. Configure the HarmonyOS SDK and environment variables + * API12, deveco-studio-5.0 or command-line-tools-5.0 * Configure Java17 * Configure environment variables (SDK, node, ohpm, hvigor) ```sh - export TOOL_HOME=/Applications/DevEco-Studio-5.0.3.300.app/Contents # For 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 + export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # For 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 ``` - 2. Download the current warehouse code `git clone https://gitee.com/openharmony-sig/flutter_flutter.git` through the code tool, and configure the environment + 2. Download the current warehouse code `git clone https://gitee.com/openharmony-sig/flutter_flutter.git` Specify the dev or master branch and configure the environment ```sh - export PATH=/bin:$PATH - + export PATH=/bin:$PATH + export PUB_CACHE=D:/PUB # Domestic mirror - export PUB_HOSTED_URL=https://pub.flutter-io.cn - export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn + export PUB_HOSTED_URL=https://pub.flutter-io.cn + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` - 3. becomes an optional parameter and may not be passed. - - Usage example: `--local-engine=src/out/` + 3. `--local-engine` becomes an optional parameter and can be obtained from the cloud by default. + - Usage example: `--local-engine=src/out/` - You can download [compiled product](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2) from this path. - The engine path points to the directory that needs to be accompanied by 'src/out'. For the configuration of all the above environment variables (for environment variable configuration under Windows, please set it in 'Edit System Environment Variables'), you can refer to the following example (please replace user and specific code path with the actual path): - ``` - # Domestic mirror - export PUB_HOSTED_URL=https://pub.flutter-io.cn - export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn - - # The flutter_flutter directory pulled from Gitee - export PATH=/home//ohos/flutter_flutter/bin:$PATH - - # HarmonyOS SDK - export TOOL_HOME=/Applications/DevEco-Studio-5.0.3.300.app/Contents # For 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 + ```sh + # Dependent cache + export PUB_CACHE=D:/PUB(Custom path) + + # Domestic mirror + export PUB_HOSTED_URL=https://pub.flutter-io.cn + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn + + # The flutter_flutter directory pulled from Gitee + export PATH=/home//ohos/flutter_flutter/bin:$PATH + + # HarmonyOS SDK + export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # For 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 ``` ## Build steps @@ -70,21 +80,27 @@ This repository is a compatible extension of Flutter SDK for the OpenHarmony pla 2. Create the project and compile the command. The compiled product is under \/ohos/entry/build/default/outputs/default/entry-default-signed.hap. ``` - # Create project - flutter create --platforms ohos + # Create project + flutter create --platforms ohos - # Enter the project root directory to compile - # Example: flutter build hap [--target-platform ohos-arm64] --local-engine=/src/out/ohos_release_arm64 --release - flutter build hap --local-engine=/home/user/engine_make/src/out/ohos_release_arm64 --release + # Go to the project root directory for compilation + # Example: flutter build hap [--target-platform ohos-arm64] [--local-engine=/src/out/ohos_release_arm64] --release + flutter build hap --release ``` 3. After discovering the ohos device through the `flutter devices` command, use `hdc -t install ` to install it. 4. You can also directly use the following command to run: -``` - # Example: flutter run --local-engine=/src/out/ohos_debug_unopt_arm64 - flutter run --local-engine=/home/user/engine_make/src/out/ohos_debug_unopt_arm64 --debug -``` + ``` + # Example: flutter run [--local-engine=/src/out/ohos_debug_unopt_arm64] -d + flutter run --debug -d + ``` + +5. Build app package command: + ``` + # Example: flutter build app --release [--local-engine=/src/out/ohos_release_arm64] local-engine(is optional) + flutter build app --release + ``` ## Compatible command list developed by OpenHarmony @@ -100,9 +116,9 @@ This repository is a compatible extension of Flutter SDK for the OpenHarmony pla | devices | Connected device discovery | flutter devices | | install | application installation | flutter install -t \ \ | | assemble | resource packaging | flutter assemble | -| build | Test application build | flutter build hap --target-platform ohos-arm64 --debug --local-engine=\ | -| build | Formal application build | flutter build hap --target-platform ohos-arm64 --release --local-engine=\ | -| run | application run | flutter run --local-engine=\ | +| build | Test application build | flutter build hap --debug [--target-platform ohos-arm64] [--local-engine=\] | +| build | Formal application build | flutter build hap --release [--target-platform ohos-arm64] [--local-engine=\] | +| run | application run | flutter run [--local-engine=\] | | attach | debug mode | flutter attach | | screenshot | screenshot | flutter screenshot | @@ -112,52 +128,61 @@ Attachment: [Flutter third-party library adaptation plan](https://docs.qq.com/sh 1. After switching to FLUTTER_STORAGE_BASE_URL, you need to delete the \/bin/cache directory and execute Flutter clean in the project before running it again. -2. Recommended version of OpenHarmony SDK: `4.0.10.3`, which can be downloaded around August 20 when it is built daily. If there are problems related to the SDK version during the compilation process, you can try to replace this version of the SDK. - -3. If an error message appears: `The SDK license agreement is not accepted`, please execute the following command and compile again: +2. If an error message appears: `The SDK license agreement is not accepted`, please execute the following command and compile again: ``` - ./ohsdkmgr install ets:9 js:9 native:9 previewer:9 toolchains:9 --sdk-directory='/home/xc/code/sdk/ohos-sdk/' --accept-license + ./ohsdkmgr install ets:9 js:9 native:9 previewer:9 toolchains:9 --sdk-directory='/home/xc/code/sdk/ohos-sdk/' --accept-license ``` -4. After switching between debug and release compilation modes, an error may be reported during operation. You can try deleting the oh_modules cache file and recompiling. +3. If you are using the Beta version of DevEco Studio and encounter the error "must have required property 'compatibleSdkVersion', location: demo/ohos/build-profile.json5:17:11" when compiling the project, Modify the hvigor/hvigor-config.json5 file by referring to section ‘6 Create the project and run Hello World’ [Configuration Plug-in] in《DevEco Studio Environment configuration guide.docx》. -5. If `flutter docker -v` prompts that ohpm cannot be found, but the environment variables are detected correctly, please ensure that you have executed the `ohpm/bin/init` command to install ohpm and check again. - -6. If you encounter the error Unsupported class file major version 61 when compiling the signature tool, it means that the current JDK version does not support it. Please lower the Java SDK version and try again. - -7. If you are using the Beta version of DevEco Studio and encounter the error "must have required property 'compatibleSdkVersion', location: demo/ohos/build-profile.json5:17:11" when compiling the project, please refer to "DevEco Studio" Modify the hvigor/hvigor-config.json5 file in the '6 Creating Projects and Running Hello World' [Configuration Plug-in] chapter in "Environment Configuration Guide.docx". - -8. If you are prompted with an installation error: `fail to verify pkcs7 file`, please execute the command +4. If you are prompted with an installation error: `fail to verify pkcs7 file`, please execute the command ``` - hdc shell param set persist.bms.ohCert.verify true + hdc shell param set persist.bms.ohCert.verify true ``` -9. Linux virtual machine cannot directly discover OpenHarmony devices through hdc +5. Linux virtual machine cannot directly discover OpenHarmony devices through hdc Solution: In the Windows host, open the hdc server. The specific instructions are as follows: ``` - hdc kill - hdc -s serverIP:8710 -m + hdc kill + hdc -s serverIP:8710 -m ``` - Configure environment variables in linux: + Configure environment variables in linux: ``` - HDC_SERVER= - HDC_SERVER_PORT=8710 + HDC_SERVER= + HDC_SERVER_PORT=8710 ``` After the configuration is completed, the flutter sdk can complete the device connection through the hdc server. You can also refer to [official guidance](https://docs.openharmony.cn/pages/v4.0/zh-cn/device-dev/subsystems/subsys-toolchain -hdc-guide.md/#hdc-client%E5%A6%82%E4%BD%95%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AEhdc-server) . -10. An error occurred when building the Hap task: Error: The hvigor depends on the npmrc file. Configure the npmrc file first. +6. An error occurred when building the Hap task: Error: The hvigor depends on the npmrc file. Configure the npmrc file first. Please create the file `.npmrc` in the user directory `~`. For this configuration, please refer to [DevEco Studio official documentation](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/environment_config -0000001052902427-V3), the edited content is as follows: ``` - registry=https://repo.huaweicloud.com/repository/npm/ - @ohos:registry=https://repo.harmonyos.com/npm/ + registry=https://repo.huaweicloud.com/repository/npm/ + @ohos:registry=https://repo.harmonyos.com/npm/ + ``` +7. Symptom Logs are lost during log query。 + Solution:Disable global logs and enable only logs in your domain + ``` -11. An error occurs when running a debug version of the Flutter application on a HarmonyOS device (release and profile versions are normal) + Step one:Disable log printing for all fields(Some special logs cannot be closed) + hdc shell hilog -b X + Step two:Open logs for your domain only + hdc shell hilog -D + indicates the level of log printing:D/I/W/E/F,is the number before the Tag + Example: + To print logs about 'A00000/XComFlutterOHOS_Native', set 'hdc shell hilog -b D -D A00000' + annotation:The above Settings will be invalid after the machine is restarted, and you need to reset them if you want to continue using them + ``` +8. If the debug signature application cannot be started on API 11BETA1, it can be resolved by changing the signature to an official signature or opening the developer mode on the mobile terminal (steps: Settings -> General -> Developer mode). + +9. If `Invalid CEN header (invalid zip64 extra data field size)` is abnormal, please replace the JDK version, see [JDK-8313765] + +10. An error occurs when running a debug version of the Flutter application on a HarmonyOS device (release and profile versions are normal) 1. Error message: `Error while initializing the Dart VM: Wrong full snapshot version, expected '8af474944053df1f0a3be6e6165fa7cf' found 'adb4292f3ec25074ca70abcd2d5c7251'` 2. Solution: Perform the following actions in sequence 1. Set environment variables `export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com` @@ -166,5 +191,76 @@ Attachment: [Flutter third-party library adaptation plan](https://docs.qq.com/sh 3. Execute `flutter run -d $DEVICE --debug` 3. Additional information: If a similar error occurs while running Android or iOS, you can also try restoring the environment variable FLUTTER_STORAGE_BASE_URL , clearing the cache, and then running again. -12. After the ROM update in Beta 2 version, anonymous memory requests are no longer supported. - 1. Reference Documents: [Explanation of Change in Anonymous Memory Execution Permission Control Policy](https://developer.huawei.com/consumer/cn/doc/harmonyos-roadmap-V5/changelogs-for-all-apps-b031-V5#%E5%8C%BF%E5%90%8D%E5%86%85%E5%AD%98%E6%89%A7%E8%A1%8C%E6%9D%83%E9%99%90%E7%AE%A1%E6%8E%A7%E7%AD%96%E7%95%A5%E5%8F%98%E6%9B%B4%E8%AF%B4%E6%98%8E) +11. After the ROM update of Beta 2 version, it no longer supports requesting anonymous memory with execution permission, resulting in debug crashing. + 1. Solution: Update flutter_flutter to a version after a44b8a6d (2024-07-25). + 2. Key logs: + + ``` + #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. Build Hap command directly execute `flutter build hap`, no longer need `--local-engine` parameter, directly from the cloud to obtain the compilation product + +13. After the environment is configured, the system crashes when the flutter command is executed。 + 1. Solution:Add git environment variable configuration in windows environment。 + ``` + export PATH=/cmd:$PATH + ``` + +14. If `flutter pub cache clean` is executed normally, `flutter clean` will report an error. If update command is executed according to the error message, it has no effect。 + 1. Solution:To avoid this problem, comment out the configuration in the build.json5 file。 + 2. Error message: + ``` + #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://gitee.com/openharmony-sig/flutter_samples/tree/master/ohos/docs/09_specifications/update_flutter_plugin_structure.md + ``` + +15. An error message indicating path verification occurs when `flutter build hap` is executed。 + 1. Solution: + · Open the ohos-project-build-profile-schema.json file in deveco installation path D:\DevEco Studio\tools\hvigor\hvigor-ohos-plugin\res\schemas。 + · Find the line containing: "pattern": "^(\\./|\\.\\./)[\\s\\S]+$" in the file and delete it。 + 2. Error message: + ``` + #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. Execute `flutter build hap` report an error。 + 1. Solution:Open the core-module-model-impl.js file in deveco installation path D:\DevEco Studio\tools\hvigor\hvigor-ohos-plugin\src\model\module。, + Modify the findBelongProjectPath method (requires administrator rights, can be saved as and replaced) + ``` + findBelongProjectPath(e) { + if (e === path_1.default.dirname(e)) { + return this.parentProject.getProjectDir() + } + } + ``` + 2. Error message: + ``` + # 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 + # /bin:$PATH - export PUB_HOSTED_URL=https://pub.flutter-io.cn - export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn + export PUB_CACHE=D:/PUB + export PATH=/bin:$PATH + export PUB_HOSTED_URL=https://pub.flutter-io.cn + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` - 3. `--local-engine` 成为可选参数,可以不传。 + 3. `--local-engine` 成为可选参数,可以不传,默认从云端获取。 - 使用示例:`--local-engine=src/out/` - 可在该路径下载[编译产物](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2) - engine路径指向需带上 `src/out` 目录 @@ -45,19 +53,22 @@ Flutter SDK 仓库 上述所有环境变量的配置(Windows下环境变量配置请在‘编辑系统环境变量’中设置),可参考下面的示例(其中user和具体代码路径请替换成实际路径): ```sh - # 国内镜像 - export PUB_HOSTED_URL=https://pub.flutter-io.cn - export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn - - # 拉取下来的flutter_flutter/bin目录 - export PATH=/home//ohos/flutter_flutter/bin:$PATH - - # HamonyOS SDK - export TOOL_HOME=/Applications/DevEco-Studio-5.0.3.300.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 + #依赖缓存 + export PUB_CACHE=D:/PUB(自定义路径) + + # 国内镜像 + export PUB_HOSTED_URL=https://pub.flutter-io.cn + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn + + # 拉取下来的flutter_flutter/bin目录 + export PATH=/home//ohos/flutter_flutter/bin:$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 ``` @@ -68,27 +79,27 @@ Flutter SDK 仓库 2. 创建工程与编译命令,编译产物在\/ohos/entry/build/default/outputs/default/entry-default-signed.hap下。 ``` - # 创建工程 - flutter create --platforms ohos + # 创建工程 + flutter create --platforms ohos - # 进入工程根目录编译 - # 示例:flutter build hap [--target-platform ohos-arm64] [--local-engine=/src/out/ohos_release_arm64] --release - flutter build hap --release + # 进入工程根目录编译 + # 示例:flutter build hap [--target-platform ohos-arm64] [--local-engine=/src/out/ohos_release_arm64] --release + flutter build hap --release ``` 3. 通过`flutter devices`指令发现ohos设备之后,使用 `hdc -t install `进行安装。 4. 也可直接使用下列指令运行: -``` - # 示例:flutter run [--local-engine=/src/out/ohos_debug_unopt_arm64] -d - flutter run --debug -d -``` + ``` + # 示例:flutter run [--local-engine=/src/out/ohos_debug_unopt_arm64] -d + flutter run --debug -d + ``` 5. 构建app包命令: -``` - # 示例:flutter build app --release [--local-engine=/src/out/ohos_release_arm64] local-engine为可选项 - flutter build app --release -``` + ``` + # 示例:flutter build app --release [--local-engine=/src/out/ohos_release_arm64] local-engine为可选项 + flutter build app --release + ``` ## 已兼容OpenHarmony开发的指令列表 @@ -119,7 +130,7 @@ Flutter SDK 仓库 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 + ./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环境配置指导.docx》中的‘6 创建工程和运行Hello World’【配置插件】章节修改 hvigor/hvigor-config.json5文件。 @@ -127,19 +138,19 @@ Flutter SDK 仓库 4. 若提示安装报错:`fail to verify pkcs7 file` 请执行指令 ``` - hdc shell param set persist.bms.ohCert.verify true + hdc shell param set persist.bms.ohCert.verify true ``` 5. linux虚拟机通过hdc无法直接发现OpenHarmony设备 解决方案:在windows宿主机中,开启hdc server,具体指令如下: ``` - hdc kill - hdc -s serverIP:8710 -m + hdc kill + hdc -s serverIP:8710 -m ``` - 在linux中配置环境变量: + 在linux中配置环境变量: ``` - HDC_SERVER= - HDC_SERVER_PORT=8710 + HDC_SERVER= + HDC_SERVER_PORT=8710 ``` 配置完成后flutter sdk可以通过hdc server完成设备连接,也可参考[官方指导](https://docs.openharmony.cn/pages/v4.0/zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md/#hdc-client%E5%A6%82%E4%BD%95%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AEhdc-server)。 @@ -150,22 +161,22 @@ Flutter SDK 仓库 请在用户目录`~`下创建文件`.npmrc`,该配置也可参考[DevEco Studio官方文档](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/environment_config-0000001052902427-V3),编辑内容如下: ``` - registry=https://repo.huaweicloud.com/repository/npm/ - @ohos:registry=https://repo.harmonyos.com/npm/ + registry=https://repo.huaweicloud.com/repository/npm/ + @ohos:registry=https://repo.harmonyos.com/npm/ ``` 7. 查日志时,存在日志丢失现象。 解决方案:关闭全局日志,只打开自己领域的日志 ``` - 步骤一:关闭所有领域的日志打印(部分特殊日志无法关闭) - hdc shell hilog -b X - 步骤二:只打开自己领域的日志 - hdc shell hilog -D - 其中为日志打印的级别:D/I/W/E/F,为Tag前面的数字 - 举例: - 打印A00000/XComFlutterOHOS_Native的日志,需要设置hdc shell hilog -b D -D A00000 - 注:上面的设置在机器重启后会失效,如果要继续使用,需要重新设置。 + 步骤一:关闭所有领域的日志打印(部分特殊日志无法关闭) + hdc shell hilog -b X + 步骤二:只打开自己领域的日志 + hdc shell hilog -D + 其中为日志打印的级别:D/I/W/E/F,为Tag前面的数字 + 举例: + 打印A00000/XComFlutterOHOS_Native的日志,需要设置hdc shell hilog -b D -D A00000 + 注:上面的设置在机器重启后会失效,如果要继续使用,需要重新设置。 ``` 8. 若Api11 Beta1版本的机器上无法启动debug签名的应用,可以通过将签名换成正式签名,或在手机端打开开发者模式解决(步骤:设置->通用->开发者模式) @@ -180,5 +191,76 @@ Flutter SDK 仓库 4. 运行 `flutter run -d $DEVICE --debug` 3. 补充信息: 运行android或ios出现类似错误,也可以尝试还原环境变量 FLUTTER_STORAGE_BASE_URL ,清除缓存后重新运行。 -11. Beta2版本的ROM更新后,不再支持申请匿名内存。 - 1. 参考文档:[匿名内存执行权限管控策略变更说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-roadmap-V5/changelogs-for-all-apps-b031-V5#%E5%8C%BF%E5%90%8D%E5%86%85%E5%AD%98%E6%89%A7%E8%A1%8C%E6%9D%83%E9%99%90%E7%AE%A1%E6%8E%A7%E7%AD%96%E7%95%A5%E5%8F%98%E6%9B%B4%E8%AF%B4%E6%98%8E) +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=/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://gitee.com/openharmony-sig/flutter_samples/tree/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 + # kOhosToLogicalKey = 2061: LogicalKeyboardKey.backslash, 2062: LogicalKeyboardKey.semicolon, // 2063: LogicalKeyboardKey.apostrophe, + 2063: LogicalKeyboardKey.quote, 2064: LogicalKeyboardKey.slash, 2067: LogicalKeyboardKey.contextMenu, 2466: LogicalKeyboardKey.compose, diff --git a/packages/flutter/lib/src/widgets/scroll_activity.dart b/packages/flutter/lib/src/widgets/scroll_activity.dart index b8b7b1fbee23b6f3e7874405cf1afa674a375dd5..57db46a2fd2dded52682a466971891966f5e3041 100644 --- a/packages/flutter/lib/src/widgets/scroll_activity.dart +++ b/packages/flutter/lib/src/widgets/scroll_activity.dart @@ -359,7 +359,7 @@ class ScrollDragController implements Drag { ) * offset.sign; } } else { - return 0.0; + return offset < 0 ? offset - 1.0 : offset + 1.0; } } } diff --git a/packages/flutter_tools/lib/src/ohos/hvigor.dart b/packages/flutter_tools/lib/src/ohos/hvigor.dart index 81e25f8eab32fe6f521615fb5eee3591bd6eec04..bea955b09bbda8e14a4d6a3b970b81b5b364ca15 100644 --- a/packages/flutter_tools/lib/src/ohos/hvigor.dart +++ b/packages/flutter_tools/lib/src/ohos/hvigor.dart @@ -65,7 +65,7 @@ void checkPlatformEnvironment(String environment, Logger? logger) { } void copyFlutterAssets(String orgPath, String desPath, Logger? logger) { - logger?.printStatus('copy from "$orgPath" to "$desPath"'); + logger?.printTrace('copy from "$orgPath" to "$desPath"'); final LocalFileSystem localFileSystem = globals.localFileSystem; copyDirectory( localFileSystem.directory(orgPath), localFileSystem.directory(desPath)); @@ -148,6 +148,7 @@ Future assembleHap( required String ohosRootPath, required String hvigorwPath, required String flavor, + required String buildMode, Logger? logger}) async { final List command = [ hvigorwPath, @@ -155,6 +156,8 @@ Future assembleHap( 'assembleHap', '-p', 'product=$flavor', + '-p', + 'buildMode=$buildMode', '--no-daemon', ]; return hvigorwTask(command, @@ -169,6 +172,7 @@ Future assembleApp( required String ohosRootPath, required String hvigorwPath, required String flavor, + required String buildMode, Logger? logger}) async { final List command = [ hvigorwPath, @@ -176,6 +180,8 @@ Future assembleApp( 'assembleApp', '-p', 'product=$flavor', + '-p', + 'buildMode=$buildMode', '--no-daemon', ]; return hvigorwTask(command, @@ -190,6 +196,8 @@ Future assembleHar( required String workPath, required String hvigorwPath, required String moduleName, + required String buildMode, + String product = 'default', Logger? logger}) async { final List command = [ hvigorwPath, @@ -199,7 +207,7 @@ Future assembleHar( '-p', 'module=$moduleName', '-p', - 'product=default', + 'product=$product', 'assembleHar', '--no-daemon', ]; @@ -216,6 +224,7 @@ Future assembleHsp( required String hvigorwPath, required String moduleName, required String flavor, + required String buildMode, Logger? logger}) async { final List command = [ hvigorwPath, @@ -226,6 +235,8 @@ Future assembleHsp( 'module=$moduleName', '-p', 'product=$flavor', + '-p', + 'buildMode=$buildMode', 'assembleHsp', '--no-daemon', ]; @@ -384,7 +395,7 @@ void cleanAndCopyFlutterRuntime( ensureParentExists(desHarPath); final File originHarFile = globals.localFileSystem.file(localEngineHarPath); originHarFile.copySync(desHarPath); - logger?.printStatus('copy from "$localEngineHarPath" to "$desHarPath"'); + logger?.printTrace('copy from "$localEngineHarPath" to "$desHarPath"'); logger?.printTrace('copy flutter runtime to project end'); } @@ -477,6 +488,7 @@ class OhosHvigorBuilder implements OhosBuilder { hvigorwPath: hvigorwPath, flavor: getFlavor( _ohosProject.getBuildProfileFile(), ohosBuildInfo.buildInfo.flavor), + buildMode: ohosBuildInfo.buildInfo.modeName, logger: _logger); status.stop(); if (errorCode != 0) { @@ -620,6 +632,7 @@ class OhosHvigorBuilder implements OhosBuilder { flavor: getFlavor( _ohosProject.getBuildProfileFile(), ohosBuildInfo.buildInfo.flavor), hvigorwPath: hvigorwPath, + buildMode: ohosBuildInfo.buildInfo.modeName, logger: _logger); status.stop(); if (errorCode1 != 0) { @@ -706,6 +719,7 @@ class OhosHvigorBuilder implements OhosBuilder { workPath: ohosProjectPath, moduleName: moduleName, hvigorwPath: hvigorwPath, + buildMode: ohosBuildInfo.buildInfo.modeName, logger: logger); if (errorCode != 0) { throwToolExit('Oops! assembleHars failed! please check log.'); @@ -753,6 +767,7 @@ class OhosHvigorBuilder implements OhosBuilder { hvigorwPath: hvigorwPath, flavor: getFlavor( project.ohos.getBuildProfileFile(), ohosBuildInfo.buildInfo.flavor), + buildMode: ohosBuildInfo.buildInfo.modeName, logger: logger); if (errorCode != 0) { throwToolExit('Oops! assembleHsps failed! please check log.'); diff --git a/packages/flutter_tools/lib/src/ohos/hvigor_utils.dart b/packages/flutter_tools/lib/src/ohos/hvigor_utils.dart index 437d9a330c2b3b741b8706bb39eac99e9ab6e81d..ea3fa101aff10e4c421bfe19093d6487981d2206 100644 --- a/packages/flutter_tools/lib/src/ohos/hvigor_utils.dart +++ b/packages/flutter_tools/lib/src/ohos/hvigor_utils.dart @@ -145,15 +145,15 @@ String getFlavor(File buildProfileFile, String? flavor) { void updateProjectVersion(FlutterProject project, BuildInfo? buildInfo) { final File targetFile = project.ohos.getAppJsonFile(); - if (targetFile.existsSync() && buildInfo != null) { + if (targetFile.existsSync()) { final String? buildNumber = validatedBuildNumberForPlatform( TargetPlatform.ohos_arm, - buildInfo.buildNumber, + buildInfo?.buildNumber ?? project.manifest.buildNumber, globals.logger, ); final String? buildName = validatedBuildNameForPlatform( TargetPlatform.ohos_arm, - buildInfo.buildName, + buildInfo?.buildName ?? project.manifest.buildName, globals.logger, ); diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 162bb0a59e3cf9ade21a867e5b0fbb4165787328..f7dd6011dac2d7c70962d5fd6c681d7f7537c11a 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -799,21 +799,21 @@ class GitTagVersion { static GitTagVersion parseOhosVersion(String version) { final RegExp versionPattern = RegExp( - r'^(\d+)\.(\d+)\.(\d+)(-ohos)?(?:-(\d+)-g([a-f0-9]+))?$'); + r'^(\d+)\.(\d+)\.(\d+)(-ohos(-\d+\.\d+\.\d+)?)?(?:-(\d+)-g([a-f0-9]+))?$'); final Match? match = versionPattern.firstMatch(version.trim()); if (match == null) { return const GitTagVersion.unknown(); } - final List matchGroups = match.groups([1, 2, 3, 4, 5, 6]); + final List matchGroups = match.groups([1, 2, 3, 4, 5, 6, 7]); final int? x = matchGroups[0] == null ? null : int.tryParse(matchGroups[0]!); final int? y = matchGroups[1] == null ? null : int.tryParse(matchGroups[1]!); final int? z = matchGroups[2] == null ? null : int.tryParse(matchGroups[2]!); final String? devString = matchGroups[3]; // count of commits past last tagged version - final int? commits = matchGroups[4] == null ? 0 : int.tryParse(matchGroups[4]!); - final String hash = matchGroups[5] ?? ''; + final int? commits = matchGroups[5] == null ? 0 : int.tryParse(matchGroups[5]!); + final String hash = matchGroups[6] ?? ''; return GitTagVersion( x: x, @@ -821,7 +821,7 @@ class GitTagVersion { z: z, commits: commits, hash: hash, - gitTag: '$x.$y.$z${devString ?? ''}', // e.g. 1.2.3-ohos + gitTag: '$x.$y.$z${devString ?? ''}', // e.g. 3.7.12-ohos-1.0.0 ); } diff --git a/packages/flutter_tools/templates/plugin_ffi/lib/projectName.dart.tmpl b/packages/flutter_tools/templates/plugin_ffi/lib/projectName.dart.tmpl index 70a6e59f7a398ca40770495dc17e780edb88cd82..572e3e8ef0188a46fc7907ba0848483178ef056b 100644 --- a/packages/flutter_tools/templates/plugin_ffi/lib/projectName.dart.tmpl +++ b/packages/flutter_tools/templates/plugin_ffi/lib/projectName.dart.tmpl @@ -11,7 +11,7 @@ import 'dart:async'; import 'dart:ffi'; import 'dart:io'; import 'dart:isolate'; - +import 'package:flutter/foundation.dart'; import '{{projectName}}_bindings_generated.dart'; /// A very short-lived native function. @@ -48,7 +48,7 @@ final DynamicLibrary _dylib = () { if (Platform.isMacOS || Platform.isIOS) { return DynamicLibrary.open('$_libName.framework/$_libName'); } - if (Platform.isAndroid || Platform.isLinux || Platform.isOhos) { + if (Platform.isAndroid || Platform.isLinux || defaultTargetPlatform == TargetPlatform.ohos) { return DynamicLibrary.open('lib$_libName.so'); } if (Platform.isWindows) {