HarmonyOS鸿蒙Next中报错:Incorrect settings found in the build-profile.json5 file.
HarmonyOS鸿蒙Next中报错:Incorrect settings found in the build-profile.json5 file. 在配置文件运行时报错:报错:Incorrect settings found in the build-profile.json5 file.
具体的信息为:SDK versions cannot be set under both app and product. Set compileSdkVersion and compatibleSdkVersion under app, or set compileSdkVersion, compatibleSdkVersion, runtimeOS, and targetSdkVersion (optional) under product.
更多关于HarmonyOS鸿蒙Next中报错:Incorrect settings found in the build-profile.json5 file.的实战教程也可以访问 https://www.itying.com/category-93-b0.html
关于报错:Incorrect settings found in the build-profile.json5 file.一般是因为项目级的build-profile.json5文件中配置存在问题。具体需要参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-project-management-2
开发者这里有具体的报错原因,主要是因为同时在项目级的build-profile.json5中和模块级(entry目录下)build-profile.json5中同时配置了sdk版本信息,配置冲突。请删除模块级(entry目录下)build-profile.json5中的sdk版本配置信息。
更多关于HarmonyOS鸿蒙Next中报错:Incorrect settings found in the build-profile.json5 file.的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
build-profile.json5文件配置错误。检查build-profile.json5文件中的sdkPath字段,确保其指向正确的HarmonyOS SDK路径。同时,验证module下的compileSdkVersion和compatibleSdkVersion版本号是否与已安装的SDK版本匹配。配置项需符合JSON5格式规范。
这个错误是因为在 build-profile.json5 文件中,SDK版本号被重复设置了。根据HarmonyOS Next的构建规则,compileSdkVersion 和 compatibleSdkVersion 这两个关键版本号只能在 app 或 product 其中一个层级进行配置,不能同时配置。
错误原因分析:
你的 build-profile.json5 文件里,很可能在 "app" 和 "product" 两个字段下都定义了 compileSdkVersion 和 compatibleSdkVersion。系统检测到了这种冲突。
解决方案: 你需要根据你的项目类型,选择一种配置方式,并删除另一处的重复配置。
方式一:在 app 层级配置(适用于大多数应用开发)
如果你的项目是一个标准的应用模块,你应该将SDK版本配置在 app 字段下。请检查并确保你的 build-profile.json5 文件结构类似如下:
{
"app": {
"signingConfigs": [],
"products": [],
"buildModeSet": [],
"compileSdkVersion": 10, // 在此处设置
"compatibleSdkVersion": 10, // 在此处设置
...
}
}
同时,确保 "product" 字段下没有 compileSdkVersion 和 compatibleSdkVersion。
方式二:在 product 层级配置(适用于需要为不同产品风味定制SDK版本的场景)
如果你的项目配置了多个 product(产品风味),并且需要为不同的产品指定不同的SDK版本,那么你应该将配置移到 product 字段下。此时,app 层级下就不能再有这些配置。
{
"app": {
"signingConfigs": [],
...
// 确保 app 层级下没有 compileSdkVersion 和 compatibleSdkVersion
},
"products": [
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": 10, // 移至 product 下
"compatibleSdkVersion": 10, // 移至 product 下
"runtimeOS": {
"compatible": "10.0.0",
"target": "10.0.0",
"releaseType": "Release"
},
"targetSdkVersion": 10 // 在 product 下,targetSdkVersion 变为可选项
}
]
}
关键点总结:
- 二选一:
compileSdkVersion和compatibleSdkVersion必须在app或product中择一配置。 - 配置位置决定配置项:
- 如果选在
app层级配置,只需设置compileSdkVersion和compatibleSdkVersion。 - 如果选在
product层级配置,则必须同时设置compileSdkVersion、compatibleSdkVersion和runtimeOS,targetSdkVersion是可选的。
- 如果选在
请打开你的 build-profile.json5 文件,根据你的项目结构,删除其中一处的重复定义即可解决此问题。

