Android building system summary

Source: Internet
Author: User

From: http://blog.csdn.net/yili_xie/article/details/5004205

It took me a month to look at Android make. On the Internet, I always saw some prawns saying that I overviewed Android make in one day, I have to lament that the strength of the prawns and the progress of the snails can be despised. However, the android make system is completely clear, and the gods who had to set up this mechanism had to worship it and burn the three-pillar high incense with sincerity, when you are amazed at the greatness of the gods, you will feel a drop in the ocean. There is no limit to the bitter sea. If you go back to the shore, just pull the water.
I will not talk much about it in the idle time. Let's look at this mechanism. Android organizes components in various systems in the form of modules. Eng's professional vocabulary is module, android can be seen in almost every directory. mk. You can simply divide all make files in Android into four types:
1. For config
This type of file mainly configures the product and board, and selects the corresponding tool based on your host and target, and sets the corresponding General Compilation options:
Build/CORE/config. mk Summary of config
Build/CORE/envsetup. mk generate dir config and so on
Build/target/product config
Build/target/board config
Build/CORE/Combo build flags config
Here we will explain the board and product here. Borad is mainly designed for hardware chip configurations, such as whether to provide certain hardware functions, such as GPU, or whether the chip supports floating point operations. Product is a pointer to the current chip configuration. It defines the personalized configuration of the product to be produced. It mainly refers to the APK configuration and the product to which the APK will be included, which APK is not provided in the current product.
Config. MK is a general concept that defines the host tools required for module compilation and how to compile various modules. For example, built_prebuilt defines how to compile the pre-compilation module. Envsetup. mk mainly reads some variables written by envsetup. Sh to the environment variables to configure the output directory during the compilation process. Combo mainly defines the compiler and compilation options that combine host and target.
2. Module compile
This type of file mainly defines how to process the Android. mk module and how to generate the target module. The generation rules of these modules are defined in config. mk. Let's take a look:
Clear_vars: = $ (build_system)/clear_vars.mk
Build_host_static_library: = $ (build_system)/host_static_library.mk
Build_host_shared_library: = $ (build_system)/host_shared_library.mk
Build_static_library: = $ (build_system)/static_library.mk
Build_raw_static_library: = $ (build_system)/raw_static_library.mk
Build_shared_library: = $ (build_system)/shared_library.mk
Build_executable: = $ (build_system)/executable. mk
Build_raw_executable: = $ (build_system)/raw_executable.mk
Build_host_executable: = $ (build_system)/host_executable.mk
Build_package: = $ (build_system)/package. mk
Build_host_prebuilt: = $ (build_system)/host_prebuilt.mk
Build_prebuilt: = $ (build_system)/prebuilt. mk
Build_multi_prebuilt: = $ (build_system)/multi_prebuilt.mk
Build_java_library: = $ (build_system)/java_library.mk
Build_static_java_library: = $ (build_system)/static_java_library.mk
Build_host_java_library: = $ (build_system)/host_java_library.mk
Build_droiddoc: = $ (build_system)/droiddoc. mk
Build_copy_headers: = $ (build_system)/copy_headers.mk
Build_key_char_map: = $ (build_system)/key_char_map.mk
Except that clear_vars is clear about local variables, all other variables correspond to a module generation rule. Each local module will include one of them to generate the target module. Most of the above. MK will contain base_rules.mk, which is the basic file for processing the module. It is recommended that you write all the local modules to see why Android. MK should be written in this way.
3. Local Module
The MAKEFILE file of the local module is Android. mk, which is almost everywhere in Android. During Android compilation, the following functions are used to traverse android in all subdirectories. MK, once found, will not continue to look for the layer sub-directory (all the top-level Android defined by your module. MK must contain android. mk ).
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. Sh -- prune = "./out" $ (subdirs) Android. mk)
Different types of local modules have different syntaxes, but they are basically the same. They only have different variables. You can refer to how to add modules as mentioned in the previous post.
Android uses local_module_tags to determine whether local modules will be compiled into the system. Product and local_module_tags are used to determine which application packages will be compiled into the system. If you do not specify local_module_tags, the default value is user. In addition, you can use buildspec. mk to specify the modules you need to compile into the system.
You can also use mm to compile the specified module, or use make clean-module_name to delete the specified module.
4. Package
This mainly refers to the build/CORE/MAKEFILE file, which defines various IMG generation methods, including ramdisk. IMG userdata. IMG system. IMG update.zip recover. IMG and so on. Let's take a look at how these IMG are generated, corresponding to several commonly used make goals:

In the actual process, we can also edit the generated files under the out directory, and then manually package the corresponding IMG to generate the appropriate IMG. The most common is to add prebuilt files to be integrated.

All makefiles use build/CORE/main. the MK file is organized together and defines a default goals: droid. When we press make in the top directory, it is equivalent to executing make droid. When make include all files, after parsing all make my files, the system will look for the rules for generating droid and generate their dependencies in sequence until all satisfied modules are compiled, then use the corresponding tool to package it into the corresponding IMG.

Basically, the android building system is organized together in this way. Let's talk about some idle things. The first is how to speed up the android compilation process, because every time Android traverses all android. mk, whether it is to compile the entire project or only compile a module. Therefore, you can save the traversal result and read the file directly next time, but it is prone to errors, so be sure to include all. mk. When adding a new file, confirm to delete the original file. Below is a makefile that I wrote to speed up compilation. Replace the following statement with the corresponding part of main. mk:
From:
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. Sh -- prune = "./out" $ (subdirs) Android. mk)
To:
Ifneq ($ (one_shot_makefile ),)
Else
Ifneq ($ (cash_mk), true)
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. Sh -- prune = "./out" $ (subdirs) Android. mk)
Else
Subdir-makefiles-cash: = $ (shell cat build/subdir_mk_cash)
Ifeq ($ (subdir-makefiles-cash ),)
$ (Warning No. mk cash, create now !)
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. Sh -- prune = "./out" $ (subdirs) Android. mk)
MK-to-file :=$ (shell echo $ (subdir_makefiles)> build/subdir_mk_cash)
Else
$ (Warning using cash MK !)
Subdir_makefiles: = $ (shell cat build/subdir_mk_cash)
Endif
Endif
Endif
Use cash_mk = true to enable the quick compilation function. Because no error detection is performed, be careful when using it.

The last one is the problem of sdk api extension. Android can compile its own SDK and expand the corresponding sdk api. Now, I have not carefully studied it, to understand only one crude method, add the corresponding class in frameworks/base/CORE/Java. If you have time in the future, study it carefully ~~

Related Article

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.