Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enabling "libc++_shared.so" to be enabled in the OpenCV android application

I wand to implement a project with OpenCV . I have imported the the OpenCV SDK in the project and i am getting the error in as follows:-

java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found

i have read your solution in stackoverflow. The link is as below:-

Android Studio CMake - shared library missing libc++_shared.so? Can CMake bundle this?

and i have tried to implement a solution from github:-

https://github.com/jomof/ndk-stl/blob/master/ndk-stl-config.cmake

I could not find any solution.

I just want "libc++_shared.so" packaged into the apk and the SDK runs properly in my project. i have no knowledge about the build tool cmake or ndk-build.

Please give a simple solution so that i can enable "libc++_shared.so" in the application so that the OpenCV project run properly.

My Error Log looks as below.

enter image description here

My Project structure looks as:-

enter image description here

Earlier i have added CMakeLists.txt as mentioned in the OpenCV SDK as

cmake_minimum_required(VERSION 3.6)

 # dummy target to bring libc++_shared.so into packages
 add_library(opencv_jni_shared STATIC dummy.cpp)

and a dummmy.cpp file that may include "libc++_shared.so" in the apk. Yet No results.

Please help with a solution.

like image 212
Ranjit Vamadevan Avatar asked Mar 16 '20 03:03

Ranjit Vamadevan


2 Answers

Try to add the following line into your build.gradle file from the app section.

arguments "-DANDROID_STL=c++_shared"

It must be added to the externalNativeBuild sub-section.

android {
    .
    .
    defaultConfig {
        .
        externalNativeBuild {
            cmake {
                .
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
}

btw: Ranjit Vamadevan, I don't see your solution here but you mentioned you found one in your comments directly. I can not answer there. Could you please share it with us too?

like image 149
sensbo Avatar answered Sep 17 '22 14:09

sensbo


This solved it for me: Put the content of the C:\Users%username%\AppData\Local\Android\sdk\ndk-bundle\sources\cxx-stl\llvm-libc++\libs%platform%\libc++_shared.so file in your jniLibs folder(s).

Found here: https://github.com/bkaradzic/bgfx/issues/1122#issuecomment-296356682

like image 37
Moraigna Avatar answered Sep 17 '22 14:09

Moraigna