且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.lang.UnsatisfiedLinkError:dlopen失败:库"/Users/..."未找到

更新时间:2022-11-05 12:16:19

我遇到了完全相同的问题,我发现在构建.so文件时,python库的库链接是错误的,而gperf库的链接是错误的没关系.
Python库的链接错误
这两个库都在cmake中以完全相同的方法导入,因此没有任何意义.
我的一个朋友告诉我这是忍者的一个bug,他们为我提供了周转"解决方案.您必须将python库导入,就好像它是Android-NDK提供的库一样(如Android或Log).

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).

该库应放在NDK库中,该库应位于<NDK PATH>/toolchains/llvm/prebuilt/<OS_related_folder>/sysroot/usr/lib/<ABI targeted>/<minSdkVersion/

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/

其中:
-NDK path是您的NDK文件夹的位置.
-OS_related_folder是os_named文件夹(在我的情况下为Windows-x86_64).
-ABI目标是将您的库编译为的ABI(arm-linux-androideabi,aarch64-linux-android等).
-minSdkVersion是您的项目的最低SDK版本号.
该信息是从CMakeCache.txt的\ app.cxx \ cmake \ debug \\文件夹中找到的.当使用find_library进行日志记录时,将显示库的路径

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

更改CMakeLists.txt以仅提供库包含,并直接按其名称链接库(对于libpython2.7.so,为python2.7)

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} )

由于python库不是Android本身提供的,因此您需要通过更改jnLibs文件夹将其打包到APK中(请参见

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)

按照以下步骤操作可以解决此问题 .so文件中的结果库链接

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