下载NDK,最好使用r8版本以后的,因为之后的版本不需要再去配置cygwin了。
解压,配置NDK的路径,windows中配置环境变量即可。
参考文件:~\docs\ANDROID-MK.html
详细阅读说明文档。
简单范例如下:
---------- cut here ------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
---------- cut here ------------------
问题:
1. 如何考虑在Android.mk中编译出多个so文件?
include $(CLEAR_VARS)
The CLEAR_VARS variable is provided by the build system and points to aspecial GNU Makefile that will clear many LOCAL_XXX variables for you(e.g. LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc...),with the exception of LOCAL_PATH. This is needed because all buildcontrol files are parsed in a single GNU Make execution context whereall variables are global.
想编译出多个库,在一个执行结束后,调用include $(CLEAR_VARS),再写新的需要编译的源文件以及定义目标文件,应该就可以实现了。
也可以通过以下方式实现
all-subdir-makefiles
Returns a list of Android.mk located in all sub-directories of the current 'my-dir' path. For example, consider the following hierarchy:
sources/foo/Android.mk
sources/foo/lib1/Android.mk
sources/foo/lib2/Android.mk
If sources/foo/Android.mk contains the single line: include $(call all-subdir-makefiles) Then it will include automatically sources/foo/lib1/Android.mk and sources/foo/lib2/Android.mk This function can be used to provide deep-nested source directory hierarchies to the build system. Note that by default, the NDK will only look for files in sources/*/Android.mk