android ndk UnsatisfiedLinkError 使用预建共享库时 [英] android ndk UnsatisfiedLinkError when using a prebuilt shared library

查看:17
本文介绍了android ndk UnsatisfiedLinkError 使用预建共享库时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个链接到另一个共享库的共享库.

I'm trying to create a shared library that links to another shared library.

这是我的主模块 Android.mk:

Here is my main module Android.mk:

TOP_LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)

LOCAL_PATH := $(TOP_LOCAL_PATH)

include $(CLEAR_VARS)

LOCAL_CPP_EXTENSION := cpp


LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ $(LOCAL_PATH)/lib/include
LOCAL_MODULE    := SightCore-jni
LOCAL_SRC_FILES := SightDemo.cpp SightCore-jni.cpp
LOCAL_SHARED_LIBRARIES := SightAPI
LOCAL_LDLIBS = -llog 

include $(BUILD_SHARED_LIBRARY)

我在 ./lib 目录中也有预构建的共享库,它有自己的 Android.mk 文件:

I also have the prebuilt shared library in ./lib directory with its own Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := SightAPI
LOCAL_SRC_FILES := libSightAPI.so
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_SHARED_LIBRARY)

SightCore-jni.cpp源文件是共享库的jni接口,使用命令加载

The SightCore-jni.cpp source file is the jni interface to the shared library and is loaded using the command

System.loadLibrary("SightCore-jni");  

在 ndk-build 过程中,我得到没有编译或链接错误.当我尝试运行应用程序并访问其中一种本机方法时,我得到了 UnsatsfiedLinkError.我注意到,如果在我的 jni 代码中禁用对 SightAPI 的引用并在 LOCAL_STATIC_LIBRARIES := SightAPI 行中输入错字,则构建成功并且没有 UnsatisfiedLinkError.
这意味着我拥有的jni代码是好的(我实际上确定它是好的......)

During the ndk-build process I get no compilation or linkage errors. When I try to run the application and access one of the native methods I get the UnsatsfiedLinkError. I noticed that if disable the references to the SightAPI in my jni code and put a typo to the LOCAL_STATIC_LIBRARIES := SightAPI line, The build is successful and there is no UnsatisfiedLinkError.
This mean that the jni code I have is good (I'm actually sure it is ok...)

所以观察如下:
如果我用预建的共享库编译共享库,我会得到一个损坏的 .so 文件.

So the observation is as follows:
If I compile the shared library with the prebuilt shared library I get a corrupted .so file.

如果我编译相同的 ndk 项目没有链接到预建的共享库,则 没问题 从 java 端加载共享库.

If I compile the same ndk project without linking to the prebuilt shared library there is no problem loading the shared library from the java side.

如果可以的话,请帮帮我.

Please help me out if you can.

提前致谢,

意大利

推荐答案

发现问题.

显然,ndk 构建系统不会自动加载引用的共享库,即使它们已在您的 Android.mk 中声明.

Apparently the ndk build system doesn't automatically load referenced shared libraries, even if they are declared in your Android.mk.

我不得不调用 System.loadLibrary(SightAPI) &System.loadLibrary("SightCore-jni") 来解决这个问题.我原以为要加载的唯一库是主库 SightCore-jni.

I had to call on System.loadLibrary(SightAPI) & System.loadLibrary("SightCore-jni") in order to solve this issue. I would have expected that the only library to load would have been the main library SightCore-jni.

嗯..我想道德是如果你想做某事,就自己做吧:)

Well..I guess the moral is If you want something done, do it yourself :)

+1 感谢 Roy Samuel 的努力和正确的直觉.

+1 to Roy Samuel for his effort and correct instincts.

我希望这对任何人都有帮助.

I hope this helps anyone.

干杯

这篇关于android ndk UnsatisfiedLinkError 使用预建共享库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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