HarmonyOS鸿蒙Next中元应用使用云开发调用 cloudFunction.call 报错 Load native module failed,如何解决
HarmonyOS鸿蒙Next中元应用使用云开发调用 cloudFunction.call 报错 Load native module failed,如何解决 使用官方文档中例子
await cloudFunction.call({
name: `fntest`,
version: '$latest',
timeout: 10 * 1000,
}).then((value: cloudFunction.FunctionResult) => {
hilog.info(HILOG_DOMAIN, TAG, `Succeeded in calling the function, result: ${JSON.stringify(value.result)}`);
}).catch((err: BusinessError) => {
hilog.error(HILOG_DOMAIN, TAG, `Failed to call the function, code: ${err.code}, message: ${err.message}`);
});
log中报错:
[default] [GetNativeOrCjsExports:50] Load native module failed, so is @hms:core.deviceCloudGateway.cloudFunction
fntest
为自定义函数名,已在云上部署,sdk版本为5.0.3(15)
更多关于HarmonyOS鸿蒙Next中元应用使用云开发调用 cloudFunction.call 报错 Load native module failed,如何解决的实战教程也可以访问 https://www.itying.com/category-93-b0.html
【解决方案】
模拟器不支持Cloud Foundation Kit(云开发服务)。
官方文档模拟器与真机的差异清楚的描述了模拟器对各种Kit的支持情况,同时对于不同系统中模拟器预置应用也有明确说明:模拟器预置应用。开发者在无真机或者模拟器不具备支持能力的情况时可以使用云调试。
更多关于HarmonyOS鸿蒙Next中元应用使用云开发调用 cloudFunction.call 报错 Load native module failed,如何解决的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
找了好几个关于云函数的文档没想到只有在这个有,云调试还不能实现devEco studio直连调试有些鸡肋,只能手写api鉴权了,
目前模拟器很多不支持,云调试需要上传app包,目前最准的调试方式还是使用真机,
感谢您的提问,为了更快解决您的问题,麻烦请补充以下信息:
这边试了下没有出现这个报错,这边是按照端云一体化创建的元服务吗?这边能否提供下完整的复现代码
import { hilog } from '@kit.PerformanceAnalysisKit';
import { cloudFunction } from '@kit.CloudFoundationKit';
import { BusinessError } from '@kit.BasicServicesKit';
const HILOG_DOMAIN = 0x0000;
const TAG = '[CloudFunction]';
@Component
export struct CloudFunction {
build() {
NavDestination() {
Column({ space: 20 }) {
Text($r('app.string.cloud_function_description'))
.width('90%')
.textAlign(TextAlign.Center)
.fontSize($r('app.float.body_font_size'))
Button($r('app.string.cloud_function_button_text'), { type: ButtonType.Normal })
.width('90%')
.height($r('app.float.number_40'))
.borderRadius($r('app.float.number_5'))
.onClick(async () => {
hilog.info(HILOG_DOMAIN, TAG, `call callIdGenerator function`);
await cloudFunction.call({
name: `fntest`,
version: '$latest',
timeout: 10 * 1000,
}).then((value: cloudFunction.FunctionResult) => {
hilog.info(HILOG_DOMAIN, TAG,
`Succeeded in calling the function, result: ${JSON.stringify(value.result)}`);
}).catch((err: BusinessError) => {
hilog.error(HILOG_DOMAIN, TAG, `Failed to call the function, code: ${err.code}, message: ${err.message}`);
});
})
}
};
}
}
楼主可以看下最新楼层的回复,模拟器暂不支持Cloud Foundation Kit(云开发服务)的,
云开发模块未正确加载导致该错误。检查项目配置中是否已正确声明云开发依赖,确认oh-package.json5
中@hw/hmscloud.js
版本兼容性。确保在module.json5
中声明云开发所需权限,包括网络访问权限。若使用模拟器,验证其网络连接正常。清理项目缓存并重新构建可解决部分加载异常。
检查云开发依赖是否已正确配置。在module.json5
中确认已添加cloudFunction
的required模块,并确保云开发SDK版本与HarmonyOS Next兼容。重新编译部署应用,验证云函数名称和版本格式是否正确。