Android source code Compilation Learning Summary
Content System source code compilation
The author before learning the Android system source code compilation, in order to be able to impress, a rough summary of the following content, I hope that the same beginners have some help.
System-Compiled initialization instructions
Initializing the Android compilation environment is simple and two-step. The first step is to open the terminal input source build/envseup.sh to load the required files.
$ source build/envseup.shincluding device/asusource build/envseup.shs/grouper/vendorsetup.sh including device/asus/tilapia/vendorsetup.sh including device/generic/armv7-a-neon/vendorsetup.sh including device/generic/armv7-a/vendorsetup.sh including device/generic/mips/vendorsetup.sh including device/generic/x86/vendorsetup.sh including device/lge/mako/vendorsetup.sh including device/samsung/maguro/vendorsetup.sh including device/samsung/manta/vendorsetup.sh including device/samsung/toroplus/vendorsetup.sh including device/samsung/toro/vendorsetup.sh including device/ti/panda/vendorsetup.sh including sdk/bash_completion/adb.bash
From the output of the command can be known, the file build/envsetup.sh in the process of loading, but also in the device directory to find those names called vendorsetup.sh files, and they are loaded into the current terminal. In addition, the Adb.bash file in the Sdk/bash_completion directory will also be loaded into the current terminal, which is used to implement the bash completion function of the ADB command. That is, after the file is loaded, we can help us automate the input of the command by pressing the TAB key when we run the ADB-related command.
The second step is to execute the command lunch as follows:
$ lunch You‘re building on Linux Lunch menu... pick a combo: 1. full-eng 2. full_x86-eng 3. vbox_x86-eng 4. full_mips-eng 5. full_grouper-userdebug 6. full_tilapia-userdebug 7. mini_armv7a_neon-userdebug 8. mini_armv7a-userdebug 9. mini_mips-userdebug 10. mini_x86-userdebug 11. full_mako-userdebug userdata.img:将被挂载为 /data,包含了应用程序相关的数据以及和用户相关的数据。 12. full_maguro-userdebug 13. full_manta-userdebug 14. full_toroplus-userdebug 15. full_toro-userdebug 16. full_panda-userdebug Which would you like? [full-eng]
We see the lunch command output a lunch menu that lists all the device models and their compilation types supported by the current Android source. For example, the first "Full-eng" means the device "full" is an emulator, and the compilation type "Eng" is the engineering machine.
After we have selected a lunch menu item ordinal (1-16), press ENTER to complete the initialization of the Android compilation environment. For example, if we choose 1, we can see the following output:
Which would you like? [full-eng] 1 ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.2 TARGET_PRODUCT=full TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a HOST_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-3.8.0-31-generic-x86_64-with-Ubuntu-13.04-raring HOST_BUILD_TYPE=release BUILD_ID=JOP40C OUT_DIR=out ============================================
We can see that the lunch command helped us set up a lot of environment variables. By setting these environment variables, the Android compilation environment is configured.
Source Code Compilation Instructions
Before executing the compilation instructions, in order to ensure that the API of the compilation environment matches the version of the source code to be compiled, we will make an API update for make Update-api , which may encounter various problems in this step, ask the reader to search the Internet for resolution until the update is complete. make instructions to compile, note: For the entire system source code compilation, must be executed under the system source code root directory.
During the compilation of the Android system, the Build/core/main.mk script is loaded through the makefile script in the root directory, and then the build/core/main.mk script loads the Build/core/makefile script. The Android system image file is generated by the Build/core/makefile script responsible for packaging.
Compiling the packaging process
- First, each module corresponding to a android.mk, corresponding to the makefile of each module, the file only need to define some variables, you can trigger the compilation of a module, different modules compiled in different ways, of course, each module must adhere to the compilation rules;
- Second, each module is independent of each other, but the use of include directives can be added to each module, such as Main.mk file, and in sequence, the final fragmented makefile files converge into the final makefile file;
- Finally, all modules are compiled and packaged through the above process.
The product of packing
All of the compilation artifacts will be located in the/out directory with the following subdirectories:
- /out/host/: This directory contains the product of Android development tools for the host. That is, the various tools in the SDK, such as: EMULATOR,ADB,AAPT, etc.
- /out/target/common/: This directory contains common compilation artifacts for devices, primarily Java application code and Java libraries.
- /out/target/product//: Contains compilation results for a specific device and platform-related C + + libraries and binaries. Where is the name of the specific target device.
- /out/dist/: Contains packages prepared for multiple distributions, copy files to the directory via "Make Disttarget", and the default compilation target does not produce the directory.
Compiling the generated image file
The most important product of Build is three image files, which are located in the/out/target/product//directory.
- System.img: System files, libraries, executables, and pre-installed applications that contain the Android OS will be mounted as root partitions.
- RAMDISK.IMG: The Linux kernel is mounted as a read-only partition at boot time, it contains the/init file and some configuration files. It is used to mount other system images and start the init process.
- USERDATA.IMG: will be mounted as/data, containing the application-related data and user-related data.
Android Source code compilation