The article about the development of Android NDK has been more, my blog also shared a lot of NDK development related experience and skills, today simply wrote a android.mk sample template for beginners reference.
This template mainly gives you some examples of the following issues in the development of Android NDK:
1. How to automatically add a list of source files that need to be compiled
2. How to add a third-party static library, dynamic library dependencies
3. How to construct a complete NDK engineering framework
Assuming our project relies on LIBMATH.A, LIBJSON.A, libffmpeg.so these third-party library files, the project contains several modules: Algorithm,core,network,utils,tests, each module has several. c/. h file, we will compile the entire project into a dynamic library and provide a calling interface to the Java layer through the functions in NATIVE_SDK.C.
So, we can do the following for the JNI directory of the Android project:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/79/76/wKioL1aSJN3zxpn0AABXdRGkz8k276.png "title=" Beec9024-9722-4f54-b289-993045aee85d.png "alt=" Wkiol1asjn3zxpn0aabxdrgkz8k276.png "/>
An example of the corresponding android.mk file is as follows (note: The project file can be viewed online in my GitHub (@Jhuster/android), or it can be downloaded from the last attachment in this post):
local_path := $ (Call my-dir) 3rd_inc_dir = $ (Local_path)/3rd/inc3RD_LIB_DIR = $ (Local_path)/3rd/libs# prebuild the 3rd libraries include $ (CLEAR_VARS) local_module := mathlocal_src_files := $ (3rd_lib_dir)/libmath.ainclude $ (PREBUILT_ static_library) include $ (clear_vars) local_module := jsonlocal_src_files := $ (3RD_LIB_ DIR)/libjson.ainclude $ (prebuilt_static_library) include $ (clear_vars) local_module := ffmpeglocal_src_files := $ (3rd_lib_dir)/libffmpeg.soinclude $ (prebuilt_shared_library) # build native sdk include $ (Clear_vars) LOCAL_MODULE := native_sdklocal_src_files := $ (subst $ (LOCAL_PATH)/,,$ (wildcard $ ( Local_path) (/SRC/ALGORITHM/*.C)) $ (subst $ (LOCAL_PATH)/,,$ (wildcard $ (Local_path)/src/core/*.c)) $ (subst $ (Local_path)/,,$ (wildcard $ (LOCAL_PATH)/src/network/* . c)) $ (subst $ (Local_path)/,,$ (wildcard $ (Local_path)/src/utils/*.c)) $ (subst $ (Local_path)/,,$ (wildcard $ (Local_path)/src/*.c)) local_c_includes := $ (3rd_inc_dir) local_c_includes := $ (LOCAL_PATH )/src local_c_includes := $ (Local_path)/src/algorithmlocal_c_includes += $ (LOCAL_PATH )/src/corelocal_c_includes += $ (Local_path)/src/networklocal_c_includes += $ (LOCAL_PATH)/ Src/utilslocal_cflags := -dandroid local_ldlibs := -llog local _static_libraries := math jsonlocal_shared_libraries := ffmpeginclude $ (BUILD_ shared_library) # build testsinclude $ (clear_vars) local_module := test.outlocal_src_files := $ (subst $ (Local_path)/,,$ (wildcard $ (Local_path)/tests/*.c)) LOCAL_ cflags := -dandroid local_c_includes := $ (Local_path)/src LOCAL_LDLIBS := -llog -fpie -pielocal_shared_libraries:= native_sdkinclude $ (BUILD_EXECUTABLE)
For ANDROID.MK, if you want to rely on a third-party library file, you must add Prebuilt_xxxx_library to Precompile, local_src_files the macro gives a list of source files that need to be compiled, where I pass subst and wildcard These two functions are implemented to automatically scan the source files in the specified directory, and finally, the executable program that can run on the ADB shell command line is compiled by Build_executable for unit testing of the code.
About Android.mk template is introduced here, have any questions, welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June get the latest articles and information.
This article is from the "jhuster column" blog, be sure to keep this source http://ticktick.blog.51cto.com/823160/1733500
Android Development Practice: ANDROID.MK Templates