ANDROID.MK parsing

Source: Internet
Author: User

The Android.mk file is used to describe to the compilation system how to compile your source code. In the case of compiling the entire project, all the ANDROID.MK found by the system will be stored in the Subdir_makefiles variable first, and then once in a single include into the entire compiled file.

(1) The android.mk file first needs to specify the Local_path variable, which is used to locate the source file.

Since android.mk and the source files that need to be compiled are in the same directory, they are defined in the following form:
local_path:=$ (call my-dir)
The above statement means that the Local_path variable defines the directory path where the cost file is located.(2) Multiple compilation modules can be defined in Android.mk, with each compiled module beginning with the include $ (clear_vars) and ending with the include $ (build_xxx). ①include $ (clear_vars) clear_vars is defined in BUILD/CORE/CLEAR_VARS.MK, it clears hundreds of variables except Local_path, thus Local_ Path is generally considered to be the starting sign of a compiled module. ②include $ (BUILD_XXX) This is the focus of the ANDROID.MK, which indicates that the source code is compiled into what the target file, such as Dynamic library, executable program, APK, etc., it is generally considered a compilation of the end of the module flag.(3) compiling an application (APK)
  Local_path: = $ (call my-dir)  include $ (clear_vars)  in the  Java subdirectory  local_src_files:= $ (call all-subdir-java-FILES)  # Name of the APK to build  local_package_name: /c8>= localpackage  # Tell it to build an APK  include $ (build_package)

(4) Compiling an application that relies on a static Java library (Static.jar)

Local_path: = $ (call my-dir in the package local_static_java_libraries:= static-    in the Java subdirectory local_src_files:= $ (call all-subdir-java-FILES) # Name of the APK To build local_package_name:= LocalPackage # The IT to build an APK include $ (build_package)

(5) Compiling an application that requires a platform key signature

Local_path: = $ (call my-dir in the Java subdirectory local_src_files:= $ (call all-subdir-java-files) # Name of the APK to build local_package_name:= localpackage  local_certificate: = Platform # Tell it to build an APK include $ (build_package)

(6) Compiling an application that needs to be preceded by a specific key

Local_path: = $ (call my-dir) include $ (clear_vars)  in the  Java subdirectory Local_ Src_files:= $ (call all-subdir-java-FILES) # Name of the APK to build local_package_name:= localpackage    local_certificate:= vendor/example/certs/app    # Tell it to build an APK include $ (build_package)

(7) Add a precompiled application

  Local_path: = $ (call my-dir)  include $ (clear_vars)  # Module name should match apk name to be Installe D.  Local_module:= localmodulename  local_src_files:= $ (local_module). apk  Local_module_ CLASS:= APPS  local_module_suffix:= $ (common_android_package_suffix)  include $ ( Build_prebuilt)

(8) Add a static Java library

  Local_path: = $ (call my-dir)  include $ (clear_vars)     in the  Java subdirectory  local_src_files:= $ (call all-subdir-java-FILES)     # Any libraries the This library depends  on Local_java_libraries:= android.test.runner     file to create  local_module: = Sample  file.  Include $ (build_static_java_library)

(9) compiling a build executable file

Local_path:= $ (call my-dir)    include $ (clear_vars)    local_module_tags:= Optional    + = \       $ (local_path)         local_src_files:= \          gpio-server.c    local_shared_ LIBRARIES:= \      libcurl \      libcutils    local_module:= gpio-server    include $ ( build_executable)    include $ (call all-makefiles-under,$ (Local_path))

(10) Compiling build dynamic libraries

Local_path:= $ (Call my-dir) include $ (clear_vars) Local_src_files:=\ Com_android_server_alarmmanagerservice.CPP\ Com_android_server_batteryservice.CPP\ Com_android_server_inputapplicationhandle.CPP\ Com_android_server_inputmanager.CPP\ Com_android_server_inputwindowhandle.CPP\ Com_android_server_lightsservice.CPP\ Com_android_server_powermanagerservice.CPP\ Com_android_server_systemserver.CPP\ Com_android_server_usbdevicemanager.CPP\ Com_android_server_usbhostmanager.CPP\ Com_android_server_vibratorservice.CPP\ Com_android_server_location_gpslocationprovider.CPP\ Com_android_server_connectivity_vpn.CPP\ Com_android_server_connectivityservice.CPP\ onload.CPPLocal_c_includes+=\ $ (jni_h_include) \ Frameworks/base/Services \ Frameworks/base/core/JNI \ External/skia/include/Core local_shared_libraries:=\ libandroid_runtime \ libcutils \ libhardware \ libhardware_legacy \ libnativehelper \ Libsystem_server \ libutils \ libui \ libinput \ libskia \ Libgui \ Libusbhost ifeq ($ (W Ith_malloc_leak_check),true) Local_cflags+= -dmalloc_leak_check endif local_module:=libandroid_servers include $ (build_shared_library)

(11) The Order of adding a compilation module to the system via ANDROID.MK is as follows

①local_path②clear_vars③local_src_files④local_cflags (optional)⑤local_module⑥local_static_libraries (optional)⑦build_xxx(ANDROID.MK) variables commonly used in the
Variable name Description
Local_path Used to determine the directory where the source code is located, it is best to put it in front of the Clear_vars variable reference, because it will not be cleared, each android.mk only need to define
Once.
Clear_vars It empties many variables (except Local_path) that start with Local_. Since all makefile are executed in a compiled environment,
The definition of a variable is theoretically global and it is necessary to clean up before each module is compiled.
Local_module Module name, you need to ensure that the entire compilation system is the only existence, and there can be no space in the middle
Local_module_path Output path of the module
Local_src_files The source files involved in the module compilation process. If it is a Java program, consider calling All-subdir-java-files to add all of the Java files in the directory (including subdirectories) at once
Because of the local_path, it is only necessary to give the file name (relative path), and the compiler system has a relatively strong derivation function, you can automatically calculate the dependency relationship.
Local_cc Used to specify the C compiler
Local_cxx Used to specify the C + + compiler
Local_cpp_extension Used to specify a special C + + file suffix name
Local_cflags Additional options for C language compilation
Local_cxxflags Additional options for C + + language compilation
Local_c_include Additional header files required for compiling C and C + + programs
Local_static_libraries List of static libraries required for compilation
Local_shared_libraries List of dynamic libraries required at compile time
Local_java_libraries Java class libraries required at compile time
Local_ldlibs Link options required at compile time
Local_copy_headers A list of header files that you need to copy when you install the application, which you need to use with the local_copy_hearers_to variable
Local_module_class Identifies the location where the compiled module was last placed. etc means placed in the/system/etc. Directory, apps is placed in the/system/app directory, Shared_libraries is placed in the/system/lib directory. If specified, the compiled module will not be placed in the compilation system and will end up in the corresponding directory in the obj directory of the out corresponding product.
Local_module_tags The current module contains a label, a module can contain multiple labels. The value of the label may be Eng, user, Debug, development, optional. Where optional is the default label.
Local_dex_preopt APK odex optimization switch, default is False
$ (call My-dir) Get the path to the current folder
$ (call all-java-files-under,<src>) Get all Java files under the specified directory
$ (call All-c-files-under, <src>) Get all C files under the specified directory
$ (call All-iaidl-files-under, <src>) Get all aidl files under the specified directory
$ (call All-makefiles-under, <folder>) Get all make files under the specified directory
$ (call intermediates-dir-for, <class>, <app_name>, Gets the target folder path of the build input
Build_host_static_library
Build_host_shared_library
Build_static_library
Build_raw_static-library
Build_shared_library
Build_executable
Build_raw_executable
Build_host_executable
Build_package
Build_host_prebuilt
Build_prebuilt
Build_multi_prebuilt
Build_java_library
Build_static_java_library
Build_host_java_library
Build_droiddoc
Build_copy_headers
Build_key_char_map
Various forms of compilation templates, such as static, dynamic library files, executables, documents, etc.

Android.mk parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.