简体   繁体   中英

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.

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

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?

Append my Android.mk code:

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

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.

I don't think System.loadLibrary links B.so or C.so to A.so. It's meant for loading the main library that you will call via JNI.

Does it work if A.so links to B.so and C.so when you build it? I'm thinking that the system should know to link them in automatically. If not, try using the uselib system call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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