3

I have a weird error where it says:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot find "./obj/local/armeabi-v7a/libsharedlibrary.so" from verneed[1] in DT_NEEDED list for "/data/data/com.my.app/cache/libnative.so"

I have tried a lot, but I don't understand it. I hope anyone out there can help me! Thanks in advance!

EDIT: It is not a diplicate of this question, as it is not the same error. The answer on that question does not help me...

Antonio Vlasic
  • 337
  • 3
  • 15
  • Possible duplicate of [Android NDK : Getting java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "signal" referenced by "libffmpeg.so"](https://stackoverflow.com/questions/28740315/android-ndk-getting-java-lang-unsatisfiedlinkerror-dlopen-failed-cannot-loca) – Zoe Nov 14 '17 at 07:19
  • It is not a duplicate. – Antonio Vlasic Nov 14 '17 at 07:24
  • Hello, how did you manage to fix the issue? Thanks in advance – Aris Panayiotou Sep 09 '20 at 08:27

1 Answers1

9

libsharedlibrary.so is missing its SONAME entry. You probably currently see something like the following:

$ readelf -dW libnative.so | grep NEEDED | grep libsharedlibrary
 0x0000000000000001 (NEEDED)             Shared library: [./obj/local/armeabi-v7a/libsharedlibrary.so]

Note that if you don't have readelf on your system it is provided in the NDK as $NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-readelf (adjust the path as necessary for your OS). Note that the architecture here doesn't actually matter. readelf is a multi-arch tool. Any toolchain's readelf will work fine.

What you should see if libsharedlibrary.so was built with SONAME is:

$ readelf -dW libnative.so | grep NEEDED | grep libsharedlibrary
 0x0000000000000001 (NEEDED)             Shared library: [libsharedlibrary.so]

You should see the following on libsharedlibrary.so:

$ readelf -dW libsharedlibrary.so | grep SONAME
 0x000000000000000e (SONAME)             Library soname: [libsharedlibrary.so]

The problem is that libsharedlibrary.so was not built with the -Wl,-soname,libsharedlibrary.so ldflag. ndk-build and CMake will do that for you, but if you're using a standalone toolchain or a custom build system then you need to provide it yourself.

If the library was built by a third-party and you're not able to rebuild it yourself, I don't think there's anything you can do. You'll need to contact the vendor and report the bug so they can fix it.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • 1
    You are right, but I have fixed the issue already before. Forgot to answer it. Your answer is accepted. – Antonio Vlasic Jan 17 '18 at 06:40
  • Any Windows users out there may find the readelf tool here `%NDK%\toolchains\llvm\prebuilt\windows-x86_64\bin\llvm-readelf.exe` – omahena Oct 06 '22 at 10:18