androidlinkerandroid-ndkunsatisfiedlinkerror

Why Android NDK's System.loadLibrary tries to load a SONAME


I have a vendor library that I need to link against: libSnpeHta.so

I successfully can link against it in the Android.mk

...
# main project
LOCAL_MODULE := mylib
LOCAL_SHARED_LIBRARIES += snpe_hta
include $(BUILD_SHARED_LIBRARY)
...
# dependency
include $(CLEAR_VARS)
LOCAL_MODULE := snpe_hta
LOCAL_SRC_FILES := $(SNPE_LIB_DIR)/libSnpeHta.so
#$(shell cp $(LOCAL_SRC_FILES) $(TARGET_OUT))
include $(PREBUILT_SHARED_LIBRARY)

Then when I run inside my main Java activity:

static {
      System.loadLibrary("mylib");
}

It tries to load this particular library by a SONAME and fails:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libQnnHta.so" not found at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667) at com.saicm.MainActivity.(MainActivity.java:49)

When I call ./aarch64-linux-android-readelf.exe -d <project_path>/lib/aarch64-android-clang8.0/libSnpeHta.so to check the dependencies of this library I get

Dynamic section at offset 0x134498 contains 28 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
 0x000000000000000e (SONAME)             Library soname: [libQnnHta.so]

I have no idea how the vendor distributes libQnnHta.so, I don't have this file, and I'm really puzzled why I need the SONAME library when I have libSnpeHta.so already


Solution

  • Just rename libSnpeHta.so to libQnnHta.so. I have no idea why the vendor named the library wrong, but the SONAME field is meant to be the name of the library.

    If that doesn't fix it, check that the library is actually being copied to your APK.