HarmonyOS鸿蒙Next中跟着第一课学习的内容 网络篇 Error Message: The resource reference '$string:Internet' is not defined. At file:
HarmonyOS鸿蒙Next中跟着第一课学习的内容 网络篇 Error Message: The resource reference ‘$string:Internet’ is not defined. At file: 在申请权限这里明明按照课程所写 但就是报错
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"phone"
],
"routerMap": "$profile:route_map",
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:startIcon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
//网络请求
"requestPermissions": [
{
"name": "ohos.permission.INTERNET",
"reason": "$string:Internet",
"usedScene": {
"abilities": [
"EntryAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.GET_NETWORK_INFO",
"reason": "$string:network_info",
"usedScene": {"abilities": ["EntryAbility"]
,
"when": "inuse"}
}
]
}
}
hvigor ERROR: Failed :entry:default@CompileResource…
hvigor ERROR: Tools execution failed.
Error Code: 11211120
Error: Resource Pack Error
Error Message: The resource reference ‘$string:Internet’ is not defined. At file: /Users/yuntianzhang/HarmonyOSDev/HttpRcpStudy/03/entry/build/default/intermediates/process_profile/default/module.json
-
Try the following:
Check whether this resource is defined anywhere.
Detail: Please check the message from tools.
更多关于HarmonyOS鸿蒙Next中跟着第一课学习的内容 网络篇 Error Message: The resource reference '$string:Internet' is not defined. At file:的实战教程也可以访问 https://www.itying.com/category-93-b0.html
修改reason字段,格式为$string: ***。string资源引用需要在string.json文件配置标签"name": “reason”,配置样例可参考资源文件示例。reason填写内容可参考权限使用理由的文案内容规范。
更多关于HarmonyOS鸿蒙Next中跟着第一课学习的内容 网络篇 Error Message: The resource reference '$string:Internet' is not defined. At file:的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
解决了
需要在element/string.json
添加相关的描述
课程中的内容忽略了这部分
该错误表明在HarmonyOS Next项目中引用了未定义的字符串资源$string:Internet
。需检查resources/base/element/string.json
文件,确认是否已声明该字符串资源。若未声明,需在string.json
中添加对应键值对,例如"name": "Internet", "value": "Internet"
。若已声明,请检查资源名称拼写及作用域是否正确。
错误提示指出 $string:Internet
资源未定义。需要在 resources/base/element/string.json
文件中添加对应的字符串资源定义。例如:
{
"string": [
{
"name": "Internet",
"value": "需要访问网络权限"
}
]
}
检查并确保该字符串资源已正确声明。