Android NDK linking

后端 未结 1 510
自闭症患者
自闭症患者 2020-11-27 18:53

I am trying to build an android application that calls into a C++ backend. This backend uses ZeroMQ for messaging. Per the android build page on the ZeroMQ guide, I have b

相关标签:
1条回答
  • 2020-11-27 19:15

    I just learnt how to compile a 2nd library and link it to my main library in android ndk. Let me see if I am of any use to you.

    The following is how I create my 2nd library (In my case, I build bullet physics library and the irrlicht rendering engine as 2 separate libraries for my game).

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_C_INCLUDES := HEADER FILES 
    LOCAL_MODULE := bullet
    LOCAL_SRC_FILES := SRC FILES
    
    LOCAL_ARM_MODE := arm
    LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK -DDISABLE_IMPORTGL
    LOCAL_LDLIBS := -ldl -llog
    
    include $(BUILD_SHARED_LIBRARY)
    

    Then copy your libxxxx.so (In my case, libbullet.so and libirrlicht.so) to your jni folder. And in your main library .mk file add the following.

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_C_INCLUDES := (includes for bullet)
    LOCAL_MODULE := bullet
    LOCAL_SRC_FILES := libbullet.so
    include $(PREBUILT_SHARED_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_C_INCLUDES := (includes for irrlicht)
    LOCAL_MODULE := irrlicht
    LOCAL_SRC_FILES := libirrlicht.so
    include $(PREBUILT_SHARED_LIBRARY)
    
    include $(CLEAR_VARS)
    
    LOCAL_C_INCLUDES := (includes for bullet + includes for irrlicht + includes for main code)
    LOCAL_SRC_FILES := main code src files
    
    LOCAL_MODULE := gamescript
    
    LOCAL_ARM_MODE   := arm
    LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK -DDISABLE_IMPORTGL
    LOCAL_LDLIBS := -lOpenSLES -landroid -ldl -llog
    
    LOCAL_SHARED_LIBRARIES := bullet irrlicht
    
    include $(BUILD_SHARED_LIBRARY)
    

    And now, add all the libraries to your java code in right order.

    System.loadLibrary("bullet");
    System.loadLibrary("irrlicht");
    System.loadLibrary("gamescript");
    
    0 讨论(0)
提交回复
热议问题