DevEco Studio使用3.1.0(API 9) build-profile.json5使用hvigo3.0.9时存有三条互斥要求报错
DevEco Studio使用3.1.0(API 9) build-profile.json5使用hvigo3.0.9时存有三条互斥要求报错
相似贴
build-profile.json5配置文件的字段详情可以参考文档 ↑该页面已于2025-5-14前失效。
报错:发生于DevEco Studio 4.0 Release.
测试设备版本HarmonyOS 4.2.0,连接USB无法被DevEco Studio 5.0识别,故安装老版本。
File-ProjectStructure中Compile SDK,Compatible SDK为3.1.0(API 9)
Settings中最新为3.1.0(API 9).
以下为hvigor-config.json5.
{
// "modelVersion": "3.0.9",
"hvigorVersion": "3.0.9",
// "hvigorVersion":"file:../dependencies/hvigor-4.4.0-rc.1.tgz",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "3.0.9"
// "@ohos/hvigor-ohos-plugin": "file:../dependencies/hvigor-ohos-plugin-4.1.1.tgz"
},
"execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
},
"logging": {
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
},
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
},
"nodeOptions": {
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
},
}
此种配置情况下,build-profile.json5如填写为
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": "3.1.0(9)",
"compatibleSdkVersion": "3.1.0(9)",
"targetSdkVersion": "3.1.0(9)",
"runtimeOS": "HarmonyOS",
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
},
其中的
"compileSdkVersion": "3.1.0(9)",
将报错
M.S.F version not supported when below API level 10
sync时将报错
hvigor ERROR: In the current configuration mode, api of 9 must be a number.
如改为"compileSdkVersion": 9
将报错Sync Failed:
Incorrect settings found in the build-profile.json5 file. The values of compileSdkVersion, compatibleSdkVersion, and targetSdkVersion (if set) must be a string.
以上配置要求之间冲突。导致无法成功Project sync.
在DevEco Studio 3.1.0(API 9)使用hvigor3.0.9时,build-profile.json5中三条互斥要求报错是由于模块配置冲突导致。检查build-profile.json5中的"buildOption"字段,确保同一模块下没有同时配置互斥的编译选项(如debug和release)。删除重复或冲突的配置项即可解决。该问题常见于多环境配置混用情况。
根据您描述的问题,这是DevEco Studio 4.0 Release版本与API 9配置之间的兼容性问题。主要矛盾点在于:
- 当使用字符串格式"3.1.0(9)“时,会报错"api of 9 must be a number”
- 当改为数字9时,又要求必须是字符串格式
建议解决方案:
- 确认hvigor版本是否与API 9完全兼容
- 尝试统一使用字符串格式"9"而非"3.1.0(9)"
- 检查build-profile.json5中所有SDK版本字段格式是否一致
典型正确配置示例:
"compileSdkVersion": "9",
"compatibleSdkVersion": "9",
"targetSdkVersion": "9"
若问题仍存在,可能需要考虑升级到更高版本的DevEco Studio或调整项目配置。