简体   繁体   English

将依赖的.so文件与ndk-build for Android链接

[英]Linking dependent .so files with ndk-build for Android

I have created a .so file that exposes a native C call to Java via JNI. 我创建了一个.so文件,该文件通过JNI公开了对Java的本地C调用。 This works well and I can deploy the app onto my Android system if I just use system libraries in my C code. 这很好用,如果我只是在C代码中使用系统库,则可以将应用程序部署到Android系统上。 However, if I want to make calls to functions in other .so files, I cannot get my project to link correctly. 但是,如果我要调用其他.so文件中的函数,则无法使我的项目正确链接。

For example, say I have the "libotherso.so" file which contains APIs defined in C that I can call from the "MyJNILibrary.c" code I'm using to generate "libMyJNILibrary.so". 例如,假设我有一个“ libotherso.so”文件,该文件包含用C定义的API,可以从我用来生成“ libMyJNILibrary.so”的“ MyJNILibrary.c”代码中调用该API。

I tried to change my Android.mk file as follows: 我试图按如下方式更改我的Android.mk文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := MyJNILibrary
LOCAL_SRC_FILES := MyJNILibrary.c

LOCAL_LDLIBS += -lotherso

include $(BUILD_SHARED_LIBRARY) 

But when I call ndk-build on this, I get errors finding -lotherso. 但是,当我对此调用ndk-build时,发现-lotherso时出现错误。 Where do I put the "libotherso.so" file so that ndk-build can pick it up? 我在哪里放置“ libotherso.so”文件,以便ndk-build可以接收它?

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := otherso
LOCAL_SRC_FILES := ../lib/libotherso.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := MyJNILibrary
LOCAL_SRC_FILES := MyJNILibrary.c
LOCAL_SHARED_LIBRARIES := otherso
include $(BUILD_SHARED_LIBRARY) 

Note that LOCAL_SRC_FILES is relative to your LOCAL_PATH. 请注意,LOCAL_SRC_FILES是相对于LOCAL_PATH的。

Don't forget to load your dependency before your own JNI library: 不要忘记在自己的JNI库之前加载依赖项:

static {
  System.loadLibrary("otherso");
  System.loadLibrary("MyJNILibrary");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM