NDK建主体工程源代码树库 [英] ndk build library outside main project source tree
问题描述
我希望使用NDK建立一个第三方库的avahi。的avahi早已Android的端口(具有有效的Android.mk)。
I wants to build a 3rd party library avahi using ndk. avahi has android port already (with valid Android.mk).
我做了什么:
我已经成功地创建一个项目,并复制所有的源$ C $ C到JNI /文件夹,运行NDK的构建。它建立libavahi.so
What I have done: I have successfully created a project and copied all the source code in to jni/ folder and run ndk-build. It builds libavahi.so
我想要做的:
而不是复制所有的源$ C $ C到JNI /文件夹的,我想它存储项目源代码树之外的文件夹中。我该怎么办?我已经看着NDK文档/导入模块,但没有类似于我的情况。
What I wants to do: Instead of copying all the source code into jni/ folder, I'd like to store it in a folder outside project source tree. What shall I do? I have looked into NDK DOCUMENTATION/Import Module but nothing is similar to my case.
新手在NDK,任何的建议表示欢迎。
Newbie in ndk, and any suggestion is welcomed.
推荐答案
您是对的,这不是的的情况下导入模块的。这就是你引用的 avihi 从本地code库仍然会 LOCAL_SHARED_LIBRARIES (参见NDK样本的 module-exports).但是,在你的 JNI / Android.mk
文件,您可以使用包含
命令到另一个文件。这个命令非常相似到的#include
语句中的 C 此文件不必是你的项目树内以相同的样本,这里是它如何能工作。:
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:
原始<一个href=\"http://mirror.yongbok.net/pub/pub/linux/android/repository/development/ndk/samples/module-exports/jni/Android.mk\">Android.mk从采样/模块的出口/ 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)
以及的外部的酒吧/ JNI / Android.mk如下:
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)
现在,这两个文件bar.c和foo.c中可以保持动物园项目外树!
Now, both files bar.c and foo.c may be kept outside the tree of the zoo project!
这篇关于NDK建主体工程源代码树库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!