Android compilation system learning and android compilation Learning

Source: Internet
Author: User

Android compilation system learning and android compilation Learning

Recently, I took over the subsequent task of setting up a new android platform project.

This article is based on the android5.1 source code provided by sprd.

I. general compilation Workflow

Our code is generally obtained from the chip vendor SPRD/MTK.

Source code compilation, generally and google official website (http://source.android.com/source/building.html) on the requirements of the same. There are three steps:

1. source build/envsetup. sh

2. lunch xxx

3. make-j8 2> & 1 | tee build. log

4. mmm "module" can be used to compile separate modules (only after full compilation can be used to compile modules)

 

Ii. Principles

Android compilation is based on the linux make command. When executing the Make command, a Makefile file is found in the current directory by default, and the code is compiled according to the commands in the Makefile file.

The most basic function of Makefile is to describe the dependencies between files and how to handle these dependencies.

The entire android source code is compiled by the Makefile file in the root directory.

Now let's take a look at what the commands in the compilation process do.

1. source build/envsetup. sh

Run the build/envsetup. sh script (ps: source xx. sh command is used to execute a script. Why not directly./xxx. sh? See this article http://blog.csdn.net/coofive/article/details/671835)

What are the tasks in the build/envsetup. sh script?

(1) traverse all the envsetup. sh files in device/xxx/and bring them all in source,

What code does envsetup. sh contain?

For example, device/sprd/zsl1805/lava/envsetup. sh

add_lunch_combo zsl1805_lava-userdebugadd_lunch_combo zsl1805_lava-user

What is add_lunch_combo? Let's ignore it. Let's look down.

(2) define various functions.

For example, lunch mmm add_lunch_combo.

Lunch: used to initialize the compiling environment, such as setting environment variables and specifying the target product model. Later

M: equivalent to executing the make command. Compile the entire Android source code.

Mm: if it is executed in the root directory of the Android source code, it is equivalent to executing the make command to compile the entire source code. If it is executed in a sub-directory under the root directory of the Android source code, it will start from this sub-directory and go up to a directory until the root directory to find whether there is an Android. mk file. If so, compile the modules described in the Android. mk file using the make command.

Mmm: It can be followed by one or more directories. It is the compilation module. For example, mmm "packages/apps/Launcher3"

Add_lunch_combo:

 1 unset LUNCH_MENU_CHOICES 2 function add_lunch_combo() 3 { 4     local new_combo=$1 5     local c 6     for c in ${LUNCH_MENU_CHOICES[@]} ; do 7         if [ "$new_combo" = "$c" ] ; then 8             return 9         fi10     done11     LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)12 }

Here we only need to know That add_lunch_combo adds "zsl1805_lava_userdebug" and "zsl1805_lava_user" to "LUNCH_MENU_CHOICES.

At this point, the work of source build/envsetup. sh is finished.

You can see in the shell command line

Including device/sprd/zsl1805/lava/vendorsetup. sh. The file is indeed loaded in.

 

2. lunch operation

Let's take a look at the lunch function code in build/envsetup. sh.

1 # print all values in "LUNCH_MENU_CHOICES"2 function print_lunch_menu () 3 {4 local uname = $ (uname) 5 echo 6 echo "You're building on" $ uname 7 echo 8 echo "Lunch menu... pick a combo: "9 10 local I = 1 11 local choice 12 for choice in $ {LUNCH_MENU_CHOICES [@]} 13 do 14 echo" $ I. $ choice "15 I =$ ($ I + 1) 16 done 17 18 echo 19} 20 21 function lunch () 22 {23 local answer24 # If only the lunch command is entered, all values in "LUNCH_MENU_CHOICES" will be printed.25 if ["$1"]; then 26 answer = $1 27 else 28 print_lunch_menu 29 echo-n "Which wocould you like? [Aosp_arm-eng] "30 read answer 31 fi 3233 # determine whether the value after lunch is the value in LUNCH_MENU_CHOICES. If yes, assign this value to selection.34 local selection = 35 36 if [-z "$ answer"] 37 then 38 selection = aosp_arm-eng 39 elif (echo-n $ answer | grep-q-e "^ [0- 9] [0-9] * $ ") 40 then 41 if [$ answer-le $ {# LUNCH_MENU_CHOICES [@]}] 42 then 43 selection =$ {LUNCH_MENU_CHOICES [$ ($ answer-1)]} 44 fi 45 elif (echo-n $ answer | grep-q-e "^ [^ \-] [^ \-] *-[^ \-] [^ \-] * $ ") 46 then 47 selection = $ answer 48 fi 49 50 if [-z "$ selection"] 51 then 52 echo 53 echo "Invalid lunch combo: $ answer "54 return 1 55 fi 56 57 export TARGET_BUILD_APPS = 58 export CONFIG_TARGET_BUILD_TYPE = 59 6061 # split the selection value to get the product and variant62 63 local product = $ (echo-n $ selection | sed-e "s/-. * $/") 64 check_product $ product 65 if [$? -Ne 0] 66 then 67 echo 68 echo "** Don't have a product spec for: '$ product'" 69 echo "** Do you have the right repo manifest? "70 product = 71 fi 72 73 local variant = $ (echo-n $ selection | sed-e" s/^ [^ \-] *-// ") 74 check_variant $ variant 75 if [$? -Ne 0] 76 then 77 echo 78 echo "** Invalid variant: '$ variant' "79 echo" ** Must be one of $ {VARIANT_CHOICES [@]} "80 echo" ** Vinton. wang -----------> variant: '$ variant' "81 export CONFIG_TARGET_BUILD_TYPE = $ (echo $ variant | tr '[a-z]' [A-Z] ') 82 echo "** Vinton. wang -----------> type: '$ CONFIG_TARGET_BUILD_TYPE' "83 variant =" userdebug "84 fi 85 86 if [-z" $ product "-o-z" $ variant "] 87 then 88 echo 89 return 1 90 fi 91# Obtain the values TARGET_PRODUCT TARGET_BUILD_VARIANT TARGET_BUILD_TYPE.92 export TARGET_PRODUCT = $ product 93 export TARGET_BUILD_VARIANT = $ variant 94 export TARGET_BUILD_TYPE = release 95 export ARCH = $ (gettargetarch) 96 echo "#############$ {ARCH }##############" 97 98 echo 99 echo100 check_hq_version101 set_stuff_for_environment # Set Environment Variables102 printconfig103}

 

In addition, the get_build_var () function is called in the check_product () and printconfig () methods.

# Get the exact value of a build variable.function get_build_var(){    T=$(gettop)    if [ ! "$T" ]; then        echo "Couldn't locate the top of the tree.  Try setting TOP." >&2        return    fi    (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \      command make --no-print-directory -f build/core/config.mk dumpvar-$1)}

That is to say, during the lunch process, build/core/config. mk is compiled.

 

Summary of the Lunch process:

1. Determine if there are no parameters

2. Determine whether the parameter is valid

3. Split the parameters to obtain TARGET_PRODUCT TARGET_BUILD_VARIANT.

4. Set Environment Variables

 

If we enter lunch directly, the following interface will appear:

You're building on Linux

  generic-eng simulator fs100-eng Lunch menu... pick a combo:       1. generic-eng       2. simulator       3. fs100-eng.....................

40. zsl1805_lava-userdebug
41. zsl1805_lava-user

 

Then we need the lunch zsl1805_lava-userdebug.

By now, the initialization of the android compiling environment is complete.

Post a piece of things we get after Initialization is complete

 

3. make

The following is the compilation. This is the case in the Makefile file in the root directory.

### DO NOT EDIT THIS FILE ###include build/core/main.mk### DO NOT EDIT THIS FILE ###

Make is actually compiled according to the main. mk compilation rules.

The entire compilation process is still quite complex. Here is a main. mk compilation, which basically covers all the compilation content. If you are interested in some details, you can refer to the following references for further study.

As long as we know, if we want to modify the process during the compilation process, we will find the corresponding. mk file according to this figure.

 

 

References:

Environment Initialization Process Analysis of Android Compiling System

Android compilation process (I): http://www.cnblogs.com/mr-raptor/archive/2012/06/07/2540359.html

Android compilation process (2): http://www.cnblogs.com/mr-raptor/archive/2012/06/08/2541571.html

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.