java.lang.UnsatisfiedLinkError:dlopen失败:库“ / home / ...未找到

时间:2019-12-17 08:12:32

标签: android android-ndk

我想将库添加到android-ndk hello-libs示例中。我查看了this个问题和其他相关问题,但它们没有解决我的问题。

在我的CMakeLists.txt中,我只是用我的库(libgengine.so)替换了gperf库(Google示例库):

add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
    ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgengine.so)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frtti -fexceptions")

add_library(hello-libs SHARED
            hello-libs.cpp)

target_include_directories(hello-libs PRIVATE
                           ${distribution_DIR}/gperf/include)

target_link_libraries(hello-libs
                      android
                      lib_gperf
                      log)

库的位置如下:

Libraries

该库是基于readelf命令为armeabi-v7a构建的:

armeabi-v7a

主要活动:

static {
        System.loadLibrary("hello-libs");
    }

当我运行应用程序时:

java.lang.UnsatisfiedLinkError: dlopen failed: library "/home/user/Downloads/ndk-samples-master/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib/armeabi-v7a/libgengine.so" not found
        at java.lang.Runtime.loadLibrary(Runtime.java:372)
        at java.lang.System.loadLibrary(System.java:1076)
        at com.example.hellolibs.MainActivity.<clinit>(MainActivity.java:36)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1095)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3083)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
        at android.app.ActivityThread.access$1100(ActivityThread.java:221)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7224)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

gperf库运行良好,我可以调用函数,但是当我想使用我的库时,会出现异常。主要问题是什么?库本身必须更改还是Java代码?任何指导都将受到欢迎。谢谢你。

0 个答案:

没有答案