Flutter开发HarmonyOS鸿蒙Next应用的时候build报错如何解决
Flutter开发HarmonyOS鸿蒙Next应用的时候build报错如何解决
【任务描述】
更新到这个DevEco Studio版本后
Build Version: 5.0.3.500, built on July 17, 2024
flutter build har -d -v
就报错了 可以辛苦老师们做下支持么。
[ +225 ms] ohpm INFO: fetch package done 1 @ohos/hypium from
https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_DevEcoSpace_901_9/da/v3/0234b44d-ec38-4ab0-a0f6-df1290e8f401/hypium-1.0.6.tgz
[ +106 ms] install completed in 0s 633ms
[ +16 ms] ohpm install --all invoke success.
[ +1 ms] hvigorw --mode module -p
module=flutter_module,flutter_boost,image_picker_ohos,path_provider_ohos,shared_preferences_ohos,url_launcher_ohos,webview_flutter_ohos,data_model_layer,url_
router@default -p product=default assembleHar --no-daemon
[+2114 ms] > 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]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:40:139'
}
{
instancePath: 'modules[3].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:52:185'
}
{
instancePath: 'modules[4].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:64:187'
}
{
instancePath: 'modules[5].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:76:197'
}
{
instancePath: 'modules[6].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:88:185'
}
{
instancePath: 'modules[7].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:100:191'
}
{
instancePath: 'modules[8].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:112:108'
}
{
instancePath: 'modules[9].srcPath',
keyword: 'pattern',
params: { pattern: '^(\\./|\\.\\./)[\\s\\S]+$' },
message: 'must match pattern "^(\\./|\\.\\./)[\\s\\S]+$"',
location: 'C:/Users/Administrator/Desktop/app_ohos/app_flutter/.ohos/build-profile.json5:124:102'
}
[ +4 ms] > hvigor ERROR: BUILD FAILED in 1 s 331 ms
[ +93 ms] hvigorw --mode module -p
module=flutter_module,flutter_boost,image_picker_ohos,path_provider_ohos,shared_preferences_ohos,url_launcher_ohos,webview_flutter_ohos,data_model_layer,url_
router@default -p product=default assembleHar --no-daemon invoke error.
[ +1 ms] "flutter har" took 41,385ms.
[ +2 ms] assembleHar error! please check log.
[ ]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 OhosHvigorBuilder.buildHar (package:flutter_tools/src/ohos/hvigor.dart:566:7)
<asynchronous suspension>
#2 BuildHarCommand.runCommand (package:flutter_tools/src/commands/build_har.dart:78:5)
<asynchronous suspension>
#3 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1257:27)
<asynchronous suspension>
#4 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#5 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#6 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:283:9)
<asynchronous suspension>
#7 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#8 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
<asynchronous suspension>
#9 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:64:9)
<asynchronous suspension>
#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#11 main (package:flutter_tools/executable.dart:91:3)
<asynchronous suspension>
[ +253 ms] ensureAnalyticsSent: 251ms
[ +1 ms] Running 0 shutdown hooks
[ +1 ms] Shutdown hooks complete
[ +1 ms] exiting with code 1
【解决方案】
【任务来源】
回退使用 commandline-tools-mac-arm64-5.0.3.404.zip 版本正常
我们回退不了,@ohos/xmpp_client必须使用5.0.3.500才能编译通过。
+1,怎么解决哈
+1,求解决
+1,求解决
规避方案如下: 找到工程目录下configuration–>build-profile.json5文件中的"modules"–>“srcPath"属性,然后按住Ctrl键,鼠标左键点击"srcPath"属性,进入到ohos-project-build-profile-schema.json文件中,将其中"properties”–>"srcPath"属性括号中的正则校验删掉,修改如下 将 “type”: “string”, “pattern”: “^(\./|\.\.//)[\s\S]+$” 改为 “type”: “string”
但是,又有新的错误
/Applications/DevEco-Studio.app/Contents/tools/node/bin/node /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw.js --sync -p product=default --analyze=normal --parallel --incremental --daemon
> hvigor hvigor client: Starting hvigor daemon.
> hvigor Hvigor Daemon started in 180 ms
> hvigor ERROR: Cannot find belonging project path for module at /
> hvigor ERROR: BUILD FAILED in 476 ms
Process finished with exit code 255
可以对照这个 PR 修改一下: https://gitee.com/openharmony-sig/flutter_flutter/pulls/275/files 然后删除 flutter_flutter/bin/cache 目录里的 flutter_tools.snapshot 和 flutter_tools.stamp 文件
5.0.3.500 编译flutter应用报错问题-规避方案:
1. 不校验路径的修改
- 使用DevEco-Studio打开以下文件 /Applications/DevEco-Studio.app/Contents/tools/hvigor/hvigor-ohos-plugin/res/schemas/ohos-project-build-profile-schema.json
- 删除校验 srcPath 的正则表达式和上一行末尾的逗号
// ...
”srcPath“: {
// ...
"type": "string"
// 删除这行配置
// "pattern": "^[\\da-zA-Z_-]+$"
}
// ...
2. 不抛出异常的修改
- 使用DevEco-Studio打开以下文件 /Applications/DevEco-Studio.app/Contents/tools/hvigor/hvigor-ohos-plugin/src/model/module/core-module-model-impl.js
- 格式化这个文件
- 修改方法 findBelongProjectPath(e)
// ...
findBelongProjectPath(e) {
if (e === path_1.default.dirname(e)) {
// throw Error(`Cannot find belonging project path for module at ${e}`);
return this.parentProject.getProjectDir();
}
// ...
}
DevEco-Studio 后续的新版本会修复这个问题。
在Flutter开发HarmonyOS鸿蒙Next应用时遇到build报错问题,通常可以从以下几个方面进行排查和解决:
-
检查Flutter和Dart版本:确保你的Flutter和Dart版本与HarmonyOS开发环境兼容。可以在Flutter官网查看最新的版本信息和兼容性说明。
-
依赖项问题:检查
pubspec.yaml
文件中的依赖项是否完整且版本正确。运行flutter pub get
确保所有依赖项都已正确下载。 -
环境配置:确认你的开发环境(如IDE、SDK等)已正确配置,特别是鸿蒙OS的SDK路径和版本。
-
编译配置:检查
build.gradle
或其他相关配置文件,确保编译选项和目标平台设置正确。 -
清理和重建:尝试运行
flutter clean
后重新构建项目,这可以解决一些缓存导致的问题。 -
查看错误日志:详细查看编译过程中的错误输出,找出具体的错误信息和可能的解决方案。
-
代码问题:检查代码中是否有特定于鸿蒙OS的API使用不当或不支持的情况。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html 。