Android compilation system

Source: Internet
Author: User
1. Android compilation steps:

Ii. initialize the compiling environment -- source build/envsetup. Sh

Three main tasks are completed in build/envsetup. Sh.

AddCodeAs follows:

  for  F  in  '/bin/ ls  vendor /*  /vendorsetup. sh vendor/  */ */vendorsetup.  Sh  device /*  /  */ vendorsetup.  Sh   2 /dev/ null   '  DO   echo  "   including $ F  "  . $ F   done   unset F  
3. Select the compilation target-lunch

Use lunch to select the compilation target. The function definition is as follows:

 Function lunch (){
Local answer
// If you call lunch with parameters, the compilation target is manually specified. Otherwise, the menu for selecting the compilation target is printed. If [ " $1 " ]; Then Answer = $ 1 Else Print_lunch_menu Echo -N " Which wocould you like? [Full-Eng] " Read answer Fi Local Selection =
// If no compilation target is set, the default value is full-Eng. Otherwise, if answer is a number, it is converted to the corresponding string representation. If [-Z " $ Answer " ] Then Selection = Full- Eng Elif ( Echo -N $ answer | Grep -Q-e " ^ [0-9] [0-9] * $ " ) Then If [$ Answer- Le $ {# lunch_menu_choices [@]}] Then Selection =$ {Lunch_menu_choices [$ ($ answer- 1 )]} Fi Elif ( Echo -N $ answer | Grep -Q-e " ^ [^ \-] [^ \-] *-[^ \-] [^ \-] * $ " ) Then Selection = $ Answer Fi
// If the string indicating the compilation target is empty, it indicates illegal selection and an error is returned. If [-Z " $ Selection " ] Then Echo Echo " Invalid lunch combo: $ answer " Return 1 Fi Export target_build_apps =
// Check whether the selected product is valid (as long as you create vendorsetup. Sh in the corresponding directory and add_lunch_combo, the corresponding items can be displayed in the lunch menu, but if the product information is not configured, it will be invalid)
Local Product = $ ( Echo -N $ selection | Sed -E " S/-. * $ // " ) Check_product $ Product If [$? -Ne 0 ] Then Echo Echo " ** Don't have a product spec for: '$ product' " Echo " ** Do you have the right repo manifest? " Product = Fi
// Parse the product and variant local variant from selection = $ ( Echo -N $ selection | Sed -E" S/^ [^ \-] *-// " ) Check_variant $ Variant If [$? -Ne 0 ] Then Echo Echo " ** Invalid variant: '$ variant' " Echo " ** Must be one of $ {variant_choices [@]} " Variant = Fi If [-Z " $ Product " -O-z " $ Variant " ] Then Echo Return 1 Fi
// Export target_prodect, target_build_variant, and target_build_type. For example, if full-Eng is selected, target_product = full, target_build_variant = ENG export target_product = $ Product export target_build_variant = $ Variant export target_build_type = Release Echo Set_stuff_for_environment printconfig}
4. Compile -- make-J8

Make must have makefile. The makefile in the android root directory simply includes a file:

1### Do not edit this file ###2Include build/CORE/Main. mk3### Do not edit this file ###

Build/CORE/Main. mk is complicated. The following figure shows the structure of Main. mk:

In Main. mk, the default compilation target is defined and the version check is performed. Then, include config. mk.

The config. mk defines the constants used to compile the target in Android. mk.

Clear_vars: = $ (build_system )/ Clear_vars.mkbuild_host_static_library: = $ (Build_system )/ Host_static_library.mkbuild_host_shared_library: = $ (Build_system )/ Host_shared_library.mkbuild_static_library: = $ (Build_system )/Static_library.mkbuild_raw_static_library: = $ (Build_system )/ Raw_static_library.mkbuild_shared_library: = $ (Build_system )/ Shared_library.mkbuild_executable: = $ (Build_system )/ Executable. mkbuild_raw_executable: = $ (Build_system )/ Raw_executable.mkbuild_host_executable: = $ (Build_system )/ Host_executable.mkbuild_package: = $ (Build_system )/ Package. mkbuild_phony_package: = $ (Build_system )/ Phony_package.mkbuild_host_prebuilt: = $ (Build_system )/Host_prebuilt.mkbuild_prebuilt: = $ (Build_system )/ Prebuilt. mkbuild_multi_prebuilt: = $ (Build_system )/ Multi_prebuilt.mkbuild_java_library: = $ (Build_system )/ Java_library.mkbuild_static_java_library: = $ (Build_system )/ Static_java_library.mkbuild_host_java_library: = $ (Build_system )/ Host_java_library.mkbuild_droiddoc: = $ (Build_system )/ Droiddoc. mkbuild_copy_headers: = $ (Build_system )/ Copy_headers.mkbuild_native_test: = $ (Build_system )/Native_test.mkbuild_host_native_test: = $ (Build_system)/host_native_test.mk

Then include/build/CORE/envsetup. sh, in envsetup. sh defines environment variables such as host_ OS and out_dir, searches for all products through include product_config.mk, checks the validity, and sets target_device according to the product selected during lunch.

In envsetup. Sh, find the boardconfig. mk File Based on target_device, configure the board, find the kernel_header, and configure the compilation tool chain.

The definitions. mk defines functions such as all_makefiles_under used to retrieve files.

Set according to target_build_variantRo. Secure and other system properties, set variables such as tags_to_install.

Next, use

 
Subdir_makefiles: =\ $ (Shell build/Tools/findleaves. py -- prune = out -- prune =. Repo -- prune =. Git $ (subdirs) Android. mk) include $ (subdir_makefiles)

Find android in all subdirectories. MK file and include it, so that in Android. the local_package_name and include $ (build_package) defined by MK can be used to set the corresponding android. the targets defined in MK are included in the compilation module. MK has the following definitions:

 
Build_package: = $ (build_system)/package. mk

Package. mk includes base_rules.mk to add local_module to all_modules.

Post_clean.mk is related to resource overlay. you can define resources in framework-res.apk without modifying the original resource file in framework.apk.

Next, include the build/CORE/MAKEFILE file, define trust targets such as bootimage and systemimage, and compile the droid (default) target through make to compile the system.

Android retrieves Android. mk from all subdirectories to collect all modules to compile the system, rather than entering each subdirectory to execute make. This makes it easy for us to add our own modules.

 

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.