I try to link against a vendor .so library. In my Android.mk
file, I define this library as
# main project
LOCAL_MODULE := mylib
LOCAL_SHARED_LIBRARIES += snpe_hta_hexagon_runtime
include $(BUILD_SHARED_LIBRARY)
# other lib
include $(CLEAR_VARS)
LOCAL_MODULE := snpe_hta_hexagon_runtime
LOCAL_SRC_FILES := $(SNPE_LIB_DIR)/libhta_hexagon_runtime_snpe.so
include $(PREBUILT_SHARED_LIBRARY)
And then when I load mylib
from the Java Activity
static {
System.loadLibrary("mylib");
}
I get an error
java.lang.UnsatisfiedLinkError: dlopen failed: library
"D:/work/test/project/android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libhta_hexagon_runtime_snpe.so"
not found: needed by
/data/app/~~4Z_rfVAZ7flNL6im3K2qWQ==/com.test.test-wrVtMvX-grcPp3fomXJSsQ==/lib/arm64/libmylib.so
in namespace classloader-namespace
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
I successfully linked against other libraries of this vendor, but this particular library is embedded into APK with an absolute path on my host machine. Why so?
EDIT:
As the comments suggested, it's indeed related to lack of SONAME inside this vendor library. Unlike the suggested solutions, I cannot recompile this vendor library with new linker flags. Thus I had to insert a SONAME inside the library file itself, become compiling my Android project. I used patchelf tool like so
patchelf --set-soname libmynewname.so <path_to_lib_file>