0

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>
Alexey S. Larionov
  • 6,555
  • 1
  • 18
  • 37
  • Possibly related: https://stackoverflow.com/questions/38230094/android-ndk-linker-wrong-path – Michael Feb 28 '23 at 10:33
  • @Michael Yes thank you, it was somehow related. In the linked post, the solution was to add compiler flags to set SONAME of the library that was created by the author of the post. In my case I had to use an external tool [patchelf](https://github.com/NixOS/patchelf) to change SONAME of the vendor library, which I cannot recompile otherwise – Alexey S. Larionov Feb 28 '23 at 11:56
  • @DanAlbert it's same as what Michael suggested. It led me to the solution, but since I can't recompile the vendor library, I had to patch the file with "pathcelf" tool – Alexey S. Larionov Mar 01 '23 at 07:25
  • So edit the answer in the other question? Or leave a comment or another answer? – Dan Albert Apr 13 '23 at 19:17

0 Answers0