ndk build library outside main project source tree

后端 未结 1 1559
悲&欢浪女
悲&欢浪女 2021-01-05 12:04

I wants to build a 3rd party library avahi using ndk. avahi has android port already (with valid Android.mk).

What I have done: I have successfully created a proje

相关标签:
1条回答
  • 2021-01-05 12:28

    You are right, this is not the case of Import Module. The way you reference the avihi library from your native code will still be as LOCAL_SHARED_LIBRARIES (see NDK sample module-exports). But in your jni/Android.mk file, you may use include command to another file. This command is very similar to #include statement in C. This file needs not to be inside your project tree. Taking the same sample, here is how it can work:

    Original Android.mk from samples/module-exports/jni:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := foo
    LOCAL_SRC_FILES := foo/foo.c
    LOCAL_CFLAGS := -DFOO=2
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
    LOCAL_EXPORT_CFLAGS := -DFOO=1
    LOCAL_EXPORT_LDLIBS := -llog
    include $(BUILD_STATIC_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := bar
    LOCAL_SRC_FILES := bar/bar.c
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
    LOCAL_STATIC_LIBRARIES := foo
    include $(BUILD_SHARED_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := zoo
    LOCAL_SRC_FILES := zoo/zoo.c
    LOCAL_SHARED_LIBRARIES := bar
    include $(BUILD_SHARED_LIBRARY)
    

    The changed file will look as follows:

    ZOO_LOCAL_PATH := $(call my-dir)
    include ~/projects/bar/jni/Android.mk
    LOCAL_PATH := $(ZOO_LOCAL_PATH)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := zoo
    LOCAL_SRC_FILES := zoo/zoo.c
    LOCAL_SHARED_LIBRARIES := bar
    include $(BUILD_SHARED_LIBRARY)
    

    And the external bar/jni/Android.mk as follows:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := foo
    LOCAL_SRC_FILES := foo/foo.c
    LOCAL_CFLAGS := -DFOO=2
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
    LOCAL_EXPORT_CFLAGS := -DFOO=1
    LOCAL_EXPORT_LDLIBS := -llog
    include $(BUILD_STATIC_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE := bar
    LOCAL_SRC_FILES := bar/bar.c
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
    LOCAL_STATIC_LIBRARIES := foo
    include $(BUILD_SHARED_LIBRARY)
    

    Now, both files bar.c and foo.c may be kept outside the tree of the zoo project!

    0 讨论(0)
提交回复
热议问题