如何在不链接的情况下将厂商.so库加入Android NDK包?
高通DSP SO库打包与运行加载权限问题
一、SO库打包难题
有几个厂商提供的.so库,需要包含进应用APK中,供高通硬件在运行时加载。这些库不与我的任何C++代码链接,且不绑定设备ABI(arm64-v8a和armeabi-v7a使用相同库文件)。
尝试用以下Android.mk配置打包时:
# My project ... LOCAL_SHARED_LIBRARIES += snpe_dsp_v65_domains_v2_skel # Library definition include $(CLEAR_VARS) LOCAL_MODULE := snpe_dsp_v65_domains_v2_skel LOCAL_SRC_FILES := $(SNPE_SDK_PATH)/lib/dsp/libsnpe_dsp_v65_domains_v2_skel.so include $(PREBUILT_SHARED_LIBRARY)
出现错误:libsnpe_dsp_v66_domains_v2_skel.so is incompatible with aarch64linux。原因是NDK会尝试链接该库,但我只需要将其打包进APK即可。如果从LOCAL_SHARED_LIBRARIES中移除该库,它既不会被链接,也不会被打包进APK——这点已通过查看project_path\build\intermediates\ndkBuild\debug\obj\local\arm64-v8a\目录下的文件确认。
二、临时打包方案与运行时权限错误
通过Makefile的cp命令复制库后,终于成功将其打包进APK,对应的Android.mk代码如下:
include $(CLEAR_VARS) LOCAL_MODULE := snpe_dsp_v65_domains_v2_skel LOCAL_SRC_FILES := $(SNPE_SDK_PATH)/lib/dsp/libsnpe_dsp_v65_domains_v2_skel.so $(shell cp $(LOCAL_SRC_FILES) $(TARGET_OUT)) include $(PREBUILT_SHARED_LIBRARY)
实际上除了$(shell cp $(LOCAL_SRC_FILES) $(TARGET_OUT))这一行,其他代码都不是必需的。
但厂商代码无法在运行时加载这些库,报错日志如下:
E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1844: Error: Device node open failed for domain 3 (errno Permission denied) E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:2158: Error 0x57: apps_dev_init failed for domain 3, errno Permission denied E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:2254: Error 0x57: open_dev (-1) failed for domain 3 E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1053: Error 0x57: remote_handle64_open failed for file:////data/app/com.example.example-qP0bP5ry9PqK3iQ1YKmeJg==/base.apk!/lib/arm64-v8a/libsnpe_dsp_v66_domains_v2_skel.so?snpe_dsp_domains_v2_skel_handle_invoke&_modver=1.0&_dom=cdsp W/OVR::Main: type=1400 audit(0.0:1165): avc: denied { read } for name="adsprpc-smd-secure" dev="tmpfs" ino=1131 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:xdsp_device:s0 tclass=chr_file permissive=0 E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1844: Error: Device node open failed for domain 3 (errno Permission denied) E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:2158: Error 0x57: apps_dev_init failed for domain 3, errno Permission denied E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:2254: Error 0x57: open_dev (-1) failed for domain 3 E/com.example.example: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1053: Error 0x57: remote_handle64_open failed for file:///libsnpe_dsp_v66_domains_v2_skel.so?snpe_dsp_domains_v2_skel_handle_invoke&_modver=1.0&_dom=cdsp
另外,通过Java代码System.loadLibrary("snpe_dsp_v66_domains_v2_skel");也无法加载,因为这些库是针对完全不同的ABI构建的,原本就应该由厂商代码负责加载。
内容的提问来源于stack exchange,提问作者Alexey S. Larionov
相关产品推荐
相关产品推荐

