java.lang.UnsatisfiedLinkError:dlopen失败:库"/Users/..."未找到 [英] java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/..." not found

查看:466
本文介绍了java.lang.UnsatisfiedLinkError:dlopen失败:库"/Users/..."未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 android-ndk hello-libs 中添加另一个库例子.

I want to add another lib into android-ndk hello-libs example.

CMakeLists.txt中,我添加:

# this is from the hello-libs sample code
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)

########## I add this after the sample code:  ###########
add_library(lib_py SHARED IMPORTED)
set_target_properties(lib_py PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libpython.so)

这:

target_link_libraries(
        hello-libs
        android
        lib_gperf

        #### this line ######
        lib_py

        log)

并将libpython.so复制到libgperf.so所在的目录中:

And copy libpython.so in the directory where libgperf.so located:

还将python标头复制到包含目录中:

Also copy the python headers into the include directory:

当我点击运行按钮时:

java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib/arm64-v8a/libpython.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)
        at com.example.hellolibs.MainActivity.<clinit>(MainActivity.java:36)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2931)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:173)
        at android.app.ActivityThread.main(ActivityThread.java:6698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

该路径存在于我的计算机中,但是为什么apk使用我的计算机路径而不是android设备路径?

The path exists in my computer, but why the apk use my computer path, but not the android device path?

然后我使用Android设备文件资源管理器,该lib位于目录中:

And I use the Android device file explorer, the lib is in the directory:

那我该如何使apk使用正确的路径?

Then how can I make the apk use the right path?

还是我错过了要添加的内容?

Or I miss something to add?

推荐答案

我遇到了完全相同的问题,我发现在构建.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

这篇关于java.lang.UnsatisfiedLinkError:dlopen失败:库"/Users/..."未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆