HarmonyOS 鸿蒙Next系统升级后,Worker无法使用、报文件地址找不到
HarmonyOS 鸿蒙Next系统升级后,Worker无法使用、报文件地址找不到
我们之前使用Worker都比较正常,最近升级了手机系统和DevEco Studio后,突然报错:
06-21 19:13:58.036 E [invalidDomain][js_worker.cpp(operator():256)]Get buffer by filepath failed.
06-21 19:13:58.036 E [invalidDomain]Dlopen absolute pathname: /system/lib64/libark_debugger.z.so
06-21 19:13:58.038 E [extractor.cpp(IsHapCompress:266)]Get entry info by name failed. fileName: ets/netty/worker/QuoteTickWorker.abc
06-21 19:13:58.038 E [zip_file.cpp(CreateFileMapper:851)]GetEntry failed hapPath ets/netty/worker/QuoteTickWorker.abc.
06-21 19:13:58.038 E [js_worker.cpp(ReadFilePathData:421)]Get secure mem failed, file <private>.
06-21 19:13:58.038 E [invalidDomain][js_worker.cpp(operator():256)]Get buffer by filepath failed.
这个文件在我们的一个hsp里面,位置都没错。然后之前都是好的,最新的系统上没法使用了:
06-21 19:13:58.036 E [invalidDomain][js_worker.cpp(operator():256)]Get buffer by filepath failed.
06-21 19:13:58.036 E [invalidDomain]Dlopen absolute pathname: /system/lib64/libark_debugger.z.so
06-21 19:13:58.038 E [extractor.cpp(IsHapCompress:266)]Get entry info by name failed. fileName: ets/netty/worker/QuoteTickWorker.abc
06-21 19:13:58.038 E [zip_file.cpp(CreateFileMapper:851)]GetEntry failed hapPath ets/netty/worker/QuoteTickWorker.abc.
06-21 19:13:58.038 E [js_worker.cpp(ReadFilePathData:421)]Get secure mem failed, file <private>.
06-21 19:13:58.038 E [invalidDomain][js_worker.cpp(operator():256)]Get buffer by filepath failed.
这个文件在我们的一个hsp里面,位置都没错。然后之前都是好的,最新的系统上没法使用了:
2 回复
可以参考下这个代码:
entry包中的WorkerPage.ets:
import { worker } from '@kit.ArkTS';
@Entry
@Component
struct WorkerPage {
@State message: string = 'Hello World';
aboutToAppear(): void {
const workerStage: worker.ThreadWorker = new worker.ThreadWorker('hsp/ets/workers/Worker.ets');
// const workerStage: worker.ThreadWorker = new worker.ThreadWorker('hap/ets/workers/Worker.ets');
workerStage.postMessage("ss")
}
build() {
RelativeContainer() {
Text(this.message)
.id('WorkerPageHelloWorld')
.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": {
'hsp': 'file:../hsp',
// "hap": 'file:../hap'
}
}
build-profile.json5:
"buildOption": {
"sourceOption": {
"workers": [
'./src/main/ets/workers/Worker.ets'
]
}
},
hsp包中的worker文件:
import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS';
const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
workerPort.onmessage = (e: MessageEvents) => {
console.log(e.data)
console.error("hsp onmessage")
}
workerPort.onmessageerror = (e: MessageEvents) => {
console.error("hsp onmessageerror")
}
workerPort.onerror = (e: ErrorEvent) => {
console.error("hsp onerror")
}
要注意的是:因为worker中无法加载ui相关的东西,所以要确保在worker导入的时候,避免导入ui相关文件
针对HarmonyOS 鸿蒙Next系统升级后,Worker无法使用并报文件地址找不到的问题,可能的原因及解决方案如下:
- 文件路径问题:确认Worker所需文件的路径是否正确,包括目录分隔符和文件名。系统升级可能导致文件路径发生变化。
- 系统权限问题:检查应用是否已声明并获得了访问所需文件的权限。系统升级后,权限设置可能恢复默认,需要重新设置。
- 系统兼容性问题:Worker可能不兼容新版本的鸿蒙系统。尝试查找是否有Worker的更新版本或联系开发者获取支持。
- 系统错误:有时系统临时错误可能导致文件无法访问。尝试重启设备,看是否能解决问题。
如果以上方法均无法解决问题,可能是由于系统层面的深层次问题导致。此时,建议直接联系官网客服以获取更专业的帮助。官网地址是:https://www.itying.com/category-93-b0.html 。