【HarmonyOS NEXT】中跨module使用hsp(Shared Library)中的资源

824 阅读1分钟

背景

HarmonyOS NEXT 中使用hsp(Shared Library)类型的module时会发现其它module无法引用hsp module中的资源,如何解决呢?想到Android中的资源访问实现是通过R资源类索引资源实现的,那么hsp虽然不能暴露资源,但是可以暴露类呀,那么方案来了,我们可以参考Android 在Harmony OS上实现类似的R资源类。

关于hsp的官方介绍,docs.openharmony.cn/pages/v4.1/…

新建Shared Library(hsp)实现R资源类

image.png

其它module 使用

引入本地hsp,module

image.png

使用R资源类中的资源

image.png