Android compilation process (1)

Source: Internet
Author: User

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

Android compilation process (3): http://www.cnblogs.com/mr-raptor/archive/2012/06/12/2547030.html

Android is open-source. Mobile phone and tablet manufacturers can customize their own mobile phone products based on their own hardware, such as Xiaomi, LePhone, and M9. Therefore, when we customize the Android source code, it is necessary to understand the Android compilation process.

If you have never done Android code compilation, then the most official compilation process is to view the Android Official Website: http://source.android.com/source/building.html

However, this is just to tell you how to compile a general-purpose system, and not to tell you the details in detail. Let's take a look at the compilation process.

+ Shards +

This article uses Android 2.1 and the FS_S5PC100 A8 Development Board developed by Huaqing vision.

+ Shards +

Follow the steps in google's compilation:

1> source build/envsetup. sh: Load command

2> lunch: select the platform compilation Option

3> make: Execute Compilation

We analyze the details of the compilation process according to the compilation steps, and finally add our own platform compilation options.

1. source build/envsetup. sh

This command is used to load all the commands used in envsetup. sh into environment variables. Let's analyze it.

The main Commands in envsetup. sh are as follows:

 

Function help () # display help information
Function get_abs_build_var () # obtain Absolute Variables
Function get_build_var () # obtain Absolute Variables
Function check_product () # Check product
Function check_variant () # Check Variables
Function setpaths () # Set the file path
Function printconfig () # print the configuration
Function set_stuff_for_environment () # Set Environment Variables
Function set_sequence_number () # Set the serial number
Function settitle () # Set the title
Function choosetype () # Set type
Function chooseproduct () # Set product
Function choosevariant () # Set variant
Function tapas () # functions the same as choosecombo
Function choosecombo () # Set compilation Parameters
Function add_lunch_combo () # Add a lunch project
Function print_lunch_menu () # print the lunch list
Function lunch () # configure lunch
Function m () # make from top
Function findmakefile () # Find makefile
Function mm () # make from current directory
Function mmm () # make the supplied directories
Function croot () # Return to the root directory
Function cproj ()
Function pid ()
Function systemstack ()
Function gdbclient ()
Function jgrep () # Find a java File
Function cgrep () # Find the c/cpp File
Function resgrep ()
Function tracedmdump ()
Function runhat ()
Function getbugreports ()
Function startviewserver ()
Function stopviewserver ()
Function isviewserverstarted ()
Function smoketest ()
Function runtest ()
Function godir () # Jump to the specified directory 405

# The add_lunch_combo function is called multiple times to add Android compilation options.
# Clear this variable. It will be built up again when the vendorsetup. sh
406 # files are encoded at the end of this file.
# Clear the LUNCH_MENU_CHOICES variable to use the compilation Option
407 unset LUNCH_MENU_CHOICES
408 function add_lunch_combo ()
409 {
410 local new_combo = $1 # obtain parameters when add_lunch_combo is called
411 local c
# Traverse the values in LUNCH_MENU_CHOICES in sequence. In fact, this value is blank when this function is called for the first time.
412 for c in $ {LUNCH_MENU_CHOICES [@]}; do
413 if ["$ new_combo" = "$ c"]; then # if the value of the parameter already exists in the LUNCH_MENU_CHOICES variable, return
414 return
415 fi
416 done
# If the parameter value does not exist, add it to the LUNCH_MENU_CHOICES variable.
417 LUNCH_MENU_CHOICES = ($ {LUNCH_MENU_CHOICES [@]} $ new_combo)
418}

# This is the system automatically added a default compilation item generic-eng
420 # add the default one here
421 add_lunch_combo generic-eng # Call the above add_lunch_combo function and pass generic-eng as the parameter
422
423 # if we're on linux, add the simulator. There is a special case
424 # in lunch to deal with the simulator
425 if ["$ (uname)" = "Linux"]; then
426 add_lunch_combo simulator
427 fi

# The following code is very important. It needs to find the vendorsetup. sh file from the vendor directory. If it is found, load it.
1037 # Execute the contents of any vendorsetup. sh files we can find.
1038 for f in '/bin/ls vendor/*/vendorsetup. sh vendor/*/build/vendorsetup. sh 2>/dev/null'
1039 do
1040 echo "including $ f"
1041. $ f # execute the found script, which is actually the compilation option defined by the vendor.
1042 done
1043 unset f

Envsetup. sh:

1. loaded the function commands used during compilation, such as help, lunch, m, mm, and mmm.
2. added two compilation options: generic-eng and simulator. These two options are the system default options.
3. find the vendorsetup under the vendor/<-vendor directory>/and vendor/<vendor directory>/build/directory. sh. If it exists, load and execute it and add the compilation options of the Product defined by the vendor.
In fact, the above 3rd items add the compilation option of the Product defined by the vendor to the compilation system. The code is add_lunch_combo xxx-xxx.

According to the above content, we can infer that if you want to define your own product compilation items, the simple method is directly in envsetup. sh Finally, add add_lunch_combo myProduct-eng. Of course, this is not in line with the final intention of the above Code. We still honestly create our company name under the vendor directory, create a new vendorsetup under the company directory. sh, add your own product compilation items in it

 

#mkdir vendor/farsight/#touch vendor/farsight/vendorsetup.sh#echo "add_lunch_combo fs100-eng" > vendor/farsight/vendorsetup.sh

 

In this way, when we execute the source build/envsetup. sh command, we can see the following information on shell:

 

including vendor/farsight/vendorsetup.sh

 
2. Follow the steps on the android official website to start executing lunch full-eng.

 

Of course, if you execute the above command, it will compile the General eng version system, not our personal system. We can execute the lunch command and it will print a selection menu, list available compilation options

If you add vendorsetup. sh in step 1, the following will appear in your options:

 

You're building on Linuxgeneric-eng simulator fs100-engLunch menu... pick a combo:     1. generic-eng     2. simulator     3. fs100-eng

 

Among them, 3rd items are the compilation items we have added.

 

The lunch command is a command defined in envsetup. sh. It allows you to select a compilation item to define the Product and global variables used in the compilation process.

We have not explained what the previous fs100-eng means, now let's explain, fs100 is the name of the product I defined, eng is the compilation type of the product, in addition to eng, there are user, userdebug, indicating:

Eng: engineering machine,

User: End user Machine

Userdebug: debug the test machine

Tests: Testing Machine

It can be seen that, except for eng and user, the other two cannot be handed over to the end user. Remember that when m8 came out, some eng engineering machines were released first, and then the user machine was released, you can use an engineering machine for replacement.

 

So what are the four types used? In fact, in main. mk shows that in the Android source code, each target (or project) directory has an Android. makefile of mk, each target Android. mk has a type declaration: LOCAL_MODULE_TAGS, which is used to specify which category the current target belongs to after compilation.

 

PS: Android. mk is not the same as makefile in Linux. It is a makefile defined by the Android compilation system to facilitate compilation into a dynamic, static library or executable program of c and c ++, or java library or android program,

 

Okay. Let's analyze what the lunch command has done?

 

Function lunch ()
{
Local answer

If ["$1"]; then
# Directly include parameters after lunch
Answer = $1
Else
# If the lunch is not followed by a parameter, the target product and variant menu of the local disk will be printed.
Print_lunch_menu
Echo-n "Which wowould you like? [Generic-eng]"
Read answer
Fi

Local selection =

If [-z "$ answer"]
Then
# If the user does not select this option in the menu, press enter, which is the default generic-eng
Selection = generic-eng
Elif ["$ answer" = "simulator"]
Then
# Simulator
Selection = simulator
Elif (echo-n $ answer | grep-q-e "^ [0-9] [0-9] * $ ")
Then
# If answer is a number from the menu, the string corresponding to the number is obtained.
If [$ answer-le $ {# LUNCH_MENU_CHOICES [@]}]
Then
Selection =$ {LUNCH_MENU_CHOICES [$ ($ answer-$ _ arrayoffset)]}
Fi
# If the answer string matches the *-* mode (* cannot start -)
Elif (echo-n $ answer | grep-q-e "^ [^ \-] [^ \-] *-[^ \-] [^ \-] * $")
Then
Selection = $ answer
Fi

If [-z "$ selection"]
Then
Echo
Echo "Invalid lunch combo: $ answer"
Return 1
Fi

# Special case the simulator
If ["$ selection" = "simulator"]
Then
# Simulator Mode
Export TARGET_PRODUCT = sim
Export TARGET_BUILD_VARIANT = eng
Export TARGET_SIMULATOR = true
Export TARGET_BUILD_TYPE = debug
Else

# Separating the products in product-variant Mode
Local product = $ (echo-n $ selection | sed-e "s/-. * $ //")

# Check. Call the check_product ()-> get_build_var ()-> build/core/config. mk, which is not expanded.
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

# Separating variant from the product-variant Mode
Local variant = $ (echo-n $ selection | sed-e "s/^ [^ \-] *-//")

# Check to see if it is within the range of (user userdebug eng)
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 environment variables. This is very important because the subsequent compilation systems depend on the variables defined here.
Export TARGET_PRODUCT = $ product
Export TARGET_BUILD_VARIANT = $ variant
Export TARGET_SIMULATOR = false
Export TARGET_BUILD_TYPE = release
Fi #! Simulator

Echo

# Set environment variables, which are not listed one by one. The simplest method is set> env.txt.
Set_stuff_for_environment
# Print some major variables and call the link printconfig ()-> get_build_var ()-> build/core/config. mk-> build/core/envsetup. mk is coorse and does not expand
Printconfig
}

 

From the above analysis, we can see that the lunch command can include parameters and do not include parameters, and finally export some important environment variables, thus affecting the compilation results of the compilation system. The exported variables are as follows (taking the actual operation as an example)

 

        TARGET_PRODUCT=fs100        TARGET_BUILD_VARIANT=eng        TARGET_SIMULATOR=false        TARGET_BUILD_TYPE=release

 
After the above two steps are completed, execute the make command, which will be analyzed in the next 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.