UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found > v4.1.0 - what I did wrong?

Hi devs,

I try to use OpenCV SDK for Android v4.5.1 in my java based application at an Android emulator. I have used different approaches which are available -e.g., like this tutorial example. In the end I got every time an error which consumed some time to find a solution or workaround for this:

W/System.err: java.lang.UnsatisfiedLinkError: dlopen failed: library “libc++_shared.so” not found

I checked all steps again, try to do it in another way, but in the end the error still be there. I opened already an issue but I guess maybe you could help me here more fast…

I found the root cause from that error already: The binaries which are located …\sdk\native\libs and copied to src\main}\jniLibs are damaged or something is missing, at least for the x86 build which I am using for my emulator. I don’t know what it is but after replacing the .so files with an older version of openCV .so files, I used v4.1.0 here, everything works fine.

Here are some information about my setup:
Android Studio: 4.1.2, NDK installed
Platform: Android, API 29, in-build Emulator (x86)
Error appears: OpenCV Android SDK > 4.1.0 - e.g., 4.5.1
Dev. Language: Java, loading native c++ libs (*.so)

My question to you is, do anybody also work with java in an Android x86 environment and could tell me what I did wrong? Possibly the binaries are corrupted since 6 releases but I don’t think so… Maybe somebody could tell me how I could fix it by my own so I could use the newest version of openCV?

Greetings :slight_smile:

I got some input fromt he parallel issue in github which was closed:

alalek
If you want to use another C++ runtime, then you should rebuild OpenCV binaries.
Refer to this Android documentation for details:
https://developer.android.com/ndk/guides/cpp-support

asmorkalov
Android applications should pack C++ standard library to APK file to use STL and other standard calls. NDK provides several versions of runtime library with different license and functionality. They have different name and are not compatible. Alexander pointed that OpenCV changed STL implementation between 4.1.0 and 4.5.1 and STL library is named differently. As soon as Java code have to load all shared libaries explicitly you have two options:

  • Change build scripts and Java code to use new STL shat is shipped with 4.5.1. New OpenCV for Android SDK already loads proper STL.
  • Rebuild OpenCV by yourself with alternative STL (may have issues with OpenCV) as Alalek mentioned.

I don’t understand all of it but maybe I could do what they suggest after some research.

Is there nobody who could help me here? Try to change the STL doesn’t work or I did something wrong… At the end only the older versions are working, since the change of the STL internally by OpenCV group, it is not useable for Android.

similar issue is described here: OpenCV Implementation in Android – "libc++_shared.so" not found – Ask Android Questions