We used the Cocos tool to compile C and C + + source code in our previous blog. In fact Cocos Tools read < Game Engineering Catalog >\proj.android\jni\ directory android.mk files, for cross-compiling and packaging.
ANDROID.MK is a compiled file, which is a small part of the GNU makefile and is used to describe C and C + + source code files to the Android NDK, how to compile, and to package operations. The default Android.mk file contents are as follows:
[HTML]View Plaincopy
- Local_path : = $ (call My-dir) ①
- Include $ (clear_vars) ②
- Local_module : = Cocos2dcpp_shared③
- Local_module_filename : = Libcocos2dcpp④
- Local_src_files : = hellocpp/main.cpp \
- .. /.. /classes/appdelegate.cpp \
- .. /.. /classes/helloworldscene.cpp⑤
- Local_c_includes : = $ (Local_path)/. /.. /classes⑥
- Local_whole_static_libraries : = Cocos2dx_static⑦
- Local_whole_static_libraries + = Cocosdenshion_static
- Local_whole_static_libraries + = Box2d_static
- Include $ (build_shared_library) ⑧
- $ (call import-module,2d) ⑨
- $ (call import-module,audio/android)
- $ (call import-module,box2d)
Here we explain the meaning of these items, ① line Local_path is the definition of the current directory variable, the variable must be defined, where MY-DIR macro, call My-dir is to return the current directory. The ② line code include $ (clear_vars) clears the local open variable, but does not include Local_path, because all variables are global.
The ③ Line code defines the Local_module variable, which must be defined to identify each module described in the Android.mk file. The name must be unique and does not contain any spaces. The ④ Line code defines the Local_module_filename variable, which is optional and allows you to redefine the name of the generated file. The filename generated in this example is libcocos2dcpp.so file.
The ⑤ Line code defines the Local_src_files variable, which describes the list of source files that will be compiled in the module. The ⑥ Line code defines the Local_c_includes variable, specifying the header file search path logical list. The ⑦ Line code defines the local_whole_static_libraries variable, which is used to specify the library module to connect to.
The ⑧ line code is include $ (build_shared_library) to generate a dynamic-link library (or shared library) that is compiled, and the file is named lib< Library module name >.so. In addition, we can use Build_static_library to tell the compilation system to generate a static link library, the file command for the lib< Library module name >.A.
The ⑨ line code $ (call import-module,2d) is a android.mk that contains another module through the directory name, where 2d is the module directory name.
The hint library is a collection of program code that does not have a main function. Libraries are divided into: Static link libraries and dynamic link libraries, the difference is that the static link library can be compiled into your execution code, the application can run in an environment without a static link library, the dynamic link library can not be compiled into your execution code, the application must be in the context of a linked library file run. In Microsoft Windows and Windows Phone Platform dynamic link library files are. dll files, static link libraries are. lib files, and the dynamic link library files on Linux and Android platforms are. So files, static link libraries are. a files; Mac OS Platform dynamic link library files such as x and iOS are. dylib files, and static link libraries are. a files.
For more information, please pay attention to the first Cocos2d-x 3.2 Edition book "Cocos2d-x: C + + volume" book Exchange Discussion website: http://www.cocoagame.net
For more exciting video courses, please follow the Cocos class: Http://v.51work6.com Welcome to join the COCOS2D-X Technical Discussion group: 257760386 Welcome to the Luxgen iOS classroom public Platform
Cocos porting to android-android.mk compiled file