简体   繁体   English

如何在android ndk中添加多个共享库?

[英]How to add multi shared libraries in android ndk?

Currently there are many shared libraries *.so in my program, but it seems the NDK only support the main shared library that will be used by jni. 当前我的程序中有很多共享库* .so,但是NDK似乎仅支持jni将使用的主共享库。

Example: Java app will use library A.so, while A.so has dependence in B, C When i build B and C to static libraries, then use them in A.so by LOCAL_STATIC_LIBRARIES, the app works well. 示例:Java应用程序将使用库A.so,而A.so在B,C中具有依赖性当我将B和C构建为静态库时,然后通过LOCAL_STATIC_LIBRARIES在A.so中使用它们,则该应用程序运行良好。 When i build B and C to shared libraries, then use them in A.so by LOCAL_SHARED_LIBRARIES, and load each of them by System.loadLibrary("..."), the app will crash in launching. 当我将B和C构建为共享库时,然后通过LOCAL_SHARED_LIBRARIES在A.so中使用它们,并通过System.loadLibrary(“ ...”)加载它们中的每一个,该应用程序将在启动时崩溃。

I want to use all other libraries as shared library so that i could keep my application flexible, how could i use multi shared libraries in android correctly? 我想将所有其他库用作共享库,以便保持应用程序的灵活性,如何正确使用android中的多个共享库?

Append my Android.mk code: 附加我的Android.mk代码:

DEPENDENCE_LIBS := gthread-2.0 gmodule-2.0 gobject-2.0 glib-2.0

ifeq ($(BUILD_STATIC),true)
    LOCAL_STATIC_LIBRARIES := $(DEPENDENCE_LIBS)
else
    LOCAL_SHARED_LIBRARIES := $(DEPENDENCE_LIBS)
endif

include $(BUILD_SHARED_LIBRARY)

if i define BUILD_STATIC as true , all works well, but if i define BUILD_STATIC as false , could not work 如果我将BUILD_STATIC定义为true ,则一切正常,但是如果我将BUILD_STATIC定义为false ,则无法工作

Actually my original way is correct, i just had a spelling error in name of library. 实际上,我原来的方式是正确的,但是库名称只是出现了拼写错误。 Now when i define BUILD_STATIC as false, and load each shared library by using System.loadLibrary("lib-name"), the whole process works correctly. 现在,当我将BUILD_STATIC定义为false并通过使用System.loadLibrary(“ lib-name”)加载每个共享库时,整个过程将正常工作。

I don't think System.loadLibrary links B.so or C.so to A.so. 我不认为System.loadLibrary将B.so或C.so链接到A.so。 It's meant for loading the main library that you will call via JNI. 它用于加载将通过JNI调用的主库。

Does it work if A.so links to B.so and C.so when you build it? 如果在构建A.so时将其链接到B.so和C.so,它是否有效? I'm thinking that the system should know to link them in automatically. 我认为系统应该知道自动链接它们。 If not, try using the uselib system call. 如果不是,请尝试使用uselib系统调用。

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

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