HAR包无法获取上下文context,建议使用hsp,可以跨包访问rawfile先使用Context.createModuleContext,根据模块名创建hsp的上下文,再用getRawFileContent获取示例:getContext().createModuleContext(‘目标hsp包名’).resourceManager.getRawFileContent((‘bundle.harmony.js’)) 参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-inner-application-context-V5\#contextcreatemodulecontext如果要用Har包,可以尝试暴露另一个Har包里的rawfile文件,给当前Har包用。比如:HarA依赖HarB,HarA想用HarB中的rawFile文件,HarB中将rawFile封装成一个方法 export 出去,在HarB的Index文件暴露 ,在HarA中import方法使用HarB封装方式为直接return文件:export function fnc() {return $rawfile('icon.png')
HAR包无法获取上下文context,建议使用hsp,可以跨包访问rawfile先使用Context.createModuleContext,根据模块名创建hsp的上下文,再用getRawFileContent获取示例:
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-inner-application-context-V5\#contextcreatemodulecontext
如果要用Har包,可以尝试暴露另一个Har包里的rawfile文件,给当前Har包用。
比如:HarA依赖HarB,HarA想用HarB中的rawFile文件,HarB中将rawFile封装成一个方法 export 出去,在HarB的Index文件暴露 ,在HarA中import方法使用HarB封装方式为直接return文件:export function fnc() {return $rawfile('icon.png')