HarmonyOS鸿蒙Next中在工程级的build-profile.json5中添加"multiProjects": true,构建工程运行后无法找到引用har包中的rawfile中的资源
HarmonyOS鸿蒙Next中在工程级的build-profile.json5中添加"multiProjects": true,构建工程运行后无法找到引用har包中的rawfile中的资源 在工程级的build-profile.json5中添加"multiProjects": true,构建工程运行后无法找到引用har包中的rawfile中的资源
3 回复
测试demo:
entry:Index.ets
~~~
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
RelativeContainer() {
Text($r('app.string.page_show'))
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
}
.height('100%')
.width('100%')
}
}
~~~
oh-package.json5
~~~
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
'library': 'file:../library'
}
}
~~~
har包
library:
resources/base/element/string.json
~~~
{
"string": [
{
"name": "page_show",
"value": "page from package"
}
]
}
~~~
工程级的build-profile.json5
~~~
{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"multiProjects": true,
"buildModeSet": [
{
"name": "debug"
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
},
{
"name": "library",
"srcPath": "./library"
}
]
}
~~~
更多关于HarmonyOS鸿蒙Next中在工程级的build-profile.json5中添加"multiProjects": true,构建工程运行后无法找到引用har包中的rawfile中的资源的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,如果你在build-profile.json5
中设置了"multiProjects": true
,但在构建工程后无法找到引用har包中的rawfile
资源,可能是由于资源路径问题。请检查以下几点:
- 资源路径配置:确保在
build-profile.json5
中的"resource"
字段正确配置了har包的资源路径。 - 资源引用方式:在代码中引用
rawfile
资源时,使用正确的相对路径或绝对路径。 - 构建顺序:确保在构建时,依赖的har包已正确构建并包含所需的资源文件。
- 模块依赖:在
oh-package.json5
中确认依赖的har包已被正确引用。
如果问题仍然存在,建议检查构建日志,查找具体的错误信息并进行针对性修复。