Java.lang.unsatisfiedlinkerror: Dlopen Failed: Library "/users/..." Not Found
Solution 1:
I encounter the exact same issue and I discovered that when the .so file is built, the library link for the python library is wrong while the link for gperf library is ok. Link error for python library Both libraries are imported with the exact same method in the cmake so it doesn't make sense. I friend of mine told me it is a bug from ninja and they provided me a "turn-around" solution. You have to import the python library as if it was an Android-NDK provided one (like Android or Log).
The library should be put in the NDK libraries, which should be located at <NDK PATH>/toolchains/llvm/prebuilt/<OS_related_folder>/sysroot/usr/lib/<ABI targeted>/<minSdkVersion/
Where:
- NDK path
is the location of your NDK folder.
- OS_related_folder
is the os_named folder (in my case windows-x86_64).
- ABI
targeted is the ABI to which your library is compiled for (arm-linux-androideabi, aarch64-linux-android, etc).
- minSdkVersion
is the number of your min SDK version of your project.
This information was found from CMakeCache.txt
, in the folder `\app.cxx\cmake\debug\\'. When using find_library for log, the path of the library is shown
Change CMakeLists.txt
to only provide library include, and directly link the library by it's name (python2.7 for libpython2.7.so)
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib SHARED native-lib.cpp)
include_directories( ${CMAKE_CURRENT_LIST_DIR}/../../../libs/python/include/ )
find_library( log-lib log ) # Optional
target_link_libraries( native-lib python2.7 ${log-lib} )
Since the python library isn't natively provided by Android, you will need to pack it to the APK by changing the jnLibs folders (see documentation)
Following these steps should fix the issue Resulting library link in .so file
Obviously, this is not a good solution. I hope my answer will draw more attention on this issue and somebody will provide a real solution to avoid such tweaks
Solution 2:
Assume path /Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib
is correct, then you can configure your JNI libs like below:
sourceSets {
release {
jniLibs.srcDirs += ["/Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib"]
}
debug {
jniLibs.srcDirs += ["/Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib"]
}
}
Try to change /Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib
if it is not your correct path to the jni libs.
Post a Comment for "Java.lang.unsatisfiedlinkerror: Dlopen Failed: Library "/users/..." Not Found"