HarmonyOS 鸿蒙Next中跳转3方库的page出现bug

HarmonyOS 鸿蒙Next中跳转3方库的page出现bug log :Error message:Invalid resource ID

Error code:9001001

Stacktrace:

    at anonymous (cropPage/src/main/ets/components/ImageCutPage.ets:95:13)

    at updateFunc (/usr1/hmos_for_system/src/increment/sourcecode/foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/stateMgmt.js:9185:1)

    at observeComponentCreation2 (/usr1/hmos_for_system/src/increment/sourcecode/foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/stateMgmt.js:9206:1)

    at anonymous (cropPage/src/main/ets/components/ImageCutPage.ets:100:27)

引入

"@mumu/crop_page": "^1.0.3"3方库 并执行
this.pageInfos.pushPath({
  name: 'crop://image_crop_page', param: Crop.pageConfig({
    src: result.resultUri,
    isSupportDark: true
  }),
  onPop: (popInfo) => {

  }
})

有大神可以看看么?因为代码问题 还是3方库配置不对?


更多关于HarmonyOS 鸿蒙Next中跳转3方库的page出现bug的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

开发者你好,此问题为引入的[@mumu/crop_page](https://gitee.com/limuyang2/ohos-crop/blob/master/cropPage/src/main/ets/components/ImageCutPage.ets)库中ImageCutPage.ets使用的getColorSync加载了资源。

【背景知识】 9001001 无效的资源id:为使用resourceManager获取自由传入的资源id不存在时的报错。在HAR开启混淆、中间码HAR、字节码HAR、跨HAP/HSP包这几种场景下建议使用getColorByNameSync加载资源。 【问题定位】

  1. 结合报错信息和9001001 无效的资源id文档中的排查步骤定位为三方库[@mumu/crop_page](https://gitee.com/limuyang2/ohos-crop/blob/master/cropPage/src/main/ets/components/ImageCutPage.ets)中ImageCutPage.ets中出现的报错。

  2. 查看ImageCutPage代码,在94行中通过getContext().resourceManager.getColorSync获取颜色资源传给了maskColor。

【分析结论】 问题原因为引入的[@mumu/crop_page](https://gitee.com/limuyang2/ohos-crop/blob/master/cropPage/src/main/ets/components/ImageCutPage.ets)库中ImageCutPage.ets使用的getColorSync加载了资源导致的报错。 【修改建议】

建议反馈给@mumu/crop_page三方库或者下载修改[@mumu/crop_page](https://gitee.com/limuyang2/ohos-crop/blob/master/cropPage/src/main/ets/components/ImageCutPage.ets)中ImageCutPage.ets的getColorSync方法,改为使用getColorByNameSync加载资源再本地重新打包加载使用。

更多关于HarmonyOS 鸿蒙Next中跳转3方库的page出现bug的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS Next中,跳转三方库页面出现bug可能涉及以下原因:页面路径配置错误、三方库未适配鸿蒙API、资源引用异常或生命周期管理不当。排查时需检查目标页面的路由声明是否正确,确保三方库版本与鸿蒙Next兼容,并验证资源ID是否冲突。可尝试更新三方库至最新版本或查看官方文档中关于页面路由的示例代码。

从错误信息和代码片段来看,问题可能出现在以下几个方面:

  1. 资源ID无效:错误代码9001001和"Invalid resource ID"表明系统无法识别或找到指定的资源。这通常发生在跳转页面时,路径或页面名称配置不正确。

  2. 三方库兼容性@mumu/crop_page库可能未完全适配HarmonyOS Next的API或资源管理机制。检查该库的版本是否支持当前HarmonyOS Next的SDK版本。

  3. 路径配置问题:在pushPath中使用的路径'crop://image_crop_page'可能与三方库中实际注册的页面路径不匹配。确认三方库文档中规定的正确路径格式。

  4. 参数传递Crop.pageConfig的参数(如srcisSupportDark)可能不符合库的预期格式,尤其是result.resultUri是否为有效的资源标识。

建议先验证三方库的集成步骤,确保依赖配置正确,并检查库的示例代码以确认路径和参数用法。如果问题持续,尝试更新库版本或查看是否有已知的兼容性问题。

回到顶部