开发者

How to add multi shared libraries in android ndk?

开发者 https://www.devze.com 2023-04-01 12:40 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消