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

查看:131
本文介绍了使用prebuilt共享库时NDK的android的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)

我也有其自身的Andr​​oid.mk文件./lib目录prebuilt共享库:

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建造过程中,我得到的没有编译或链接的错误。 当我尝试运行应用程序和访问的本地方法之一,我得到了UnsatsfiedLinkError。 我注意到,如果停用提到了SightAPI在我的JNI code,把一个错字到LOCAL_STATIC_LIBRARIES:= SightAPI线,构建成功并没有的UnsatisfiedLinkError
。 这意味着,JNI code我已经是很好的(实际上,我确信它是确定...)

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

所以,观察如下:
如果我编译共享库的与prebuilt 共享库,我得到一个损坏 .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项目的没有链接到prebuilt 共享库有没有问题从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构建系统的不会自动加载引用的共享库,即使它们在你的Andr​​oid.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猜测寓意是如果你想要做的事,做自己:)

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

+1罗伊·塞缪尔为他的努力和正确的本能。

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

我希望这可以帮助任何人。

I hope this helps anyone.

干杯

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

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