HarmonyOS 鸿蒙Next混淆后resourceManager取不到资源
HarmonyOS 鸿蒙Next混淆后resourceManager取不到资源
<markdown _ngcontent-dvn-c237="" class="markdownPreContainer">
在Har包的某个页面的aboutToAppear()中,通过以下代码获取相应资源:
try {
let res:Resource = $r('app.media.correct');
let id = res.id;
console.info(`res = ${res}, id = ${id}`)
//let drawableDescriptor = //getContext(this).resourceManager.getDrawableDescriptor(0x02000099);
let drawableDescriptor = getContext(this).resourceManager.getDrawableDescriptor(id);
let temp = drawableDescriptor.getPixelMap(); //获取PixelMap后做处理...
console.info('Succeed in creating pixelmap.')
} catch (e) {
let error = e as BusinessError;
console.error('Failed to create pixelmap: ' + error.code + ', ' + error.message)
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 4px; right: 8px; font-size: 14px;">复制</button>
日志: 主工程引har包,har为debug,或release下关闭混淆,都调用正常 res = [object Object],id = 16777387 Succeed in creating pixelmap.
一旦har包开启混淆: res = [object Object],id = -1 Failed to create pixelmap: 9001001, Resource id invalid
注:
- 混淆文件中没有写内容;
- 混淆后的resourceTable.h中:
放开注释的代码行依然报错const int32_t MEDIA_CORRECT = 0x02000099;
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 4px; right: 8px; font-size: 14px;">复制</button>
关于HarmonyOS 鸿蒙Next混淆后resourceManager取不到资源的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
2 回复
自己回答吧。参考 https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-app-code-ob-V5
- HAR开启混淆后资源ID为-1,ResourceManager等通过ID获取资源的API不再生效。
参考HAR,可以尝试使用resourceManager.getStringByName。
有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html