I. Introduction of ANDROID.MK
ANDROID.MK is an makefile file provided by Android that specifies such things as compiling generated so library names, referenced header file directories,. c/.cpp files that need to be compiled, and. A static library files. To master the JNI, we must master Android.mk's grammatical norm.
Its basic format is as follows:
[CPP]View Plaincopy print?
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- ................
- Local_xxx: = xxx
- Local_module: = Hello-jni
- Local_src_files: = Hello-jni.c
- Local_xxx: = xxx
- ................
- Include $ (build_shared_library)
The Local_path variable developed the path of the. MK, $ (call My-dir) calls the NDK internal function to get the path to the current. mk File
Include $ (clear_vars) clears the value of all local_xxx variables except Local_path
The middle of the ellipsis is the setting of module parameters, including: module name, module source file, module type, compiled module storage location, and compiled platform, etc.
Include $ (build_xxx_xxx) executes the NDK default script, which collects all defined local_xxx variables after the include $ (clear_vars) script, and then builds the module based on them.
Second, the ANDROID.MK grammar explanation
Local_path: = $ (call My-dir)
Each android.mk file must start with a definition of local_path. It is used to find source files in the development tree. Macro My-dir is provided by the build system. Returns the directory path that contains the ANDROID.MK.
Include $ (clear_vars)
The Clear_vars variable is provided by the build system. and points to a specified GNU Makefile, which is responsible for cleaning up many local_xxx.
For example: Local_module, Local_src_files, local_static_libraries and so on. But do not clean local_path.
This cleanup action is necessary because all compiled control files are parsed and executed by the same GNU make, and their variables are global. So we can avoid the mutual influence after cleaning.
Local_module: = Hello-jni
The Local_module module must be defined to represent each module in the ANDROID.MK. Names must be unique and contain no spaces. The Build system automatically adds the appropriate prefixes and suffixes. For example, Foo, to produce a dynamic library, generates libfoo.so. Note, however, that if the module name is set to: Libfoo. Generates libfoo.so. No more prefixes
Local_module_path: =$ (target_root_out) specifies the destination address of the last generated module
Target_root_out: Root file system, path is Out/target/product/generic/root
Target_out:system file system, path is Out/target/product/generic/system
Target_out_data:data file system, path is Out/target/product/generic/data
In addition to the above, the NDK also provides a number of other target_xxx_xxx variables that are used to copy the generated modules to different paths in the output directory
Default is Target_out
Local_src_files: = Hello-jni.c
The local_src_files variable must contain a/C + + source code that will be packaged as a module. Instead of listing header files, the build System automatically helps us identify dependent files. The default C + + source extension is. cpp. can also be modified, by local_cpp_extension
Include $ (build_shared_library)
Build_shared_library: is a variable provided by the build system that points to a GNU Makefile Script.
It is responsible for collecting all local_xxx information since the last call to include $ (clear_vars). and decide what to compile.
Build_static_library: Compile as a static library.
Build_shared_library: Compiling as a dynamic library
Build_executable: Compiled to native C executable program
Build_prebuilt: The module is pre-compiled
The NDK also defines a number of other build_xxx_xxx variables, which are used to specify how the module is generated.
Iii. Examples of Use
[CPP]View Plaincopy print?
- #编译静态库
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- Local_module = Libhellos
- Local_cflags = $ (l_cflags)
- Local_src_files = HELLOS.C
- Local_c_includes = $ (includes)
- Local_shared_libraries: = Libcutils
- Local_copy_headers_to: = Libhellos
- Local_copy_headers: = Hellos.h
- Include $ (build_static_library)
- #编译动态库
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- Local_module = Libhellod
- Local_cflags = $ (l_cflags)
- Local_src_files = HELLOD.C
- Local_c_includes = $ (includes)
- Local_shared_libraries: = Libcutils
- Local_copy_headers_to: = Libhellod
- Local_copy_headers: = Hellod.h
- Include $ (build_shared_library)
- #使用静态库
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- Local_module: = hellos
- Local_static_libraries: = Libhellos
- Local_shared_libraries: =
- Local_ldlibs + =-ldl
- Local_cflags: = $ (l_cflags)
- Local_src_files: = MAINS.C
- Local_c_includes: = $ (includes)
- Include $ (build_executable)
- #使用动态库
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- Local_module: = Hellod
- Local_module_tags: = Debug
- Local_shared_libraries: = libc libcutils Libhellod
- Local_ldlibs + =-ldl
- Local_cflags: = $ (l_cflags)
- Local_src_files: = MAIND.C
- Local_c_includes: = $ (includes)
- Include $ (build_executable)
- #拷贝文件到指定目录
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- Local_module: = bt_vendor.conf
- Local_module_class: = ETC
- Local_module_path: = $ (target_out)/etc/bluetooth
- Local_module_tags: = Eng
- Local_src_files: = $ (Local_module)
- Include $ (build_prebuilt)
- #拷贝动态库到指定目录
- Local_path: = $ (call My-dir)
- Include $ (clear_vars)
- #the data or Lib want to copy
- Local_module: = libxxx.so
- Local_module_class: = shared_libraries
- Local_module_path: = $ (android_out_shared_libraries)
- Local_src_files: = lib/$ (Local_module)
- Override_build_module_path: = $ (target_out_intermediate_libraries)
- Include $ (build_prebuilt)
Reference article:
Http://www.cnblogs.com/wainiwann/p/3837936.html
http://blog.csdn.net/ly131420/article/details/9619269
http://blog.csdn.net/mawl2002/article/details/6118522
ANDROID.MK Usage Explanation