In-depth introduction-Android system migration and platform development (2)-Prepare the android Development Environment

Source: Internet
Author: User
Tags root access
Compile Android source code

Android compilation details are provided on the official website of Android.

Http://source.android.com/source/building.html

 

Initialize the compiling environment

Switch to the android source code directory:

$ cd WORKING_DIRECTORY

Run the following command to load the commands and environment variables used in the compilation process:

$ source build/envsetup.sh

Select compilation options

Run the following command to select a compilation item from the list:

$ lunchYou're building on Linux Lunch menu... pick a combo:     1. full-eng     2.full_x86-eng     3.vbox_x86-eng     4.full_maguro-userdebug     5.full_tuna-userdebug     6.full_panda-eng

We choose: 1, that is, to compile the full-Eng goal, of course, we can also directly specify the compilation items, as shown below:

$ lunch full-eng

The lunch command prints or sets the compilation item set in the current system. The full-Eng compilation item consists of two parts, the first half is full, indicating that the target device is an android simulator. The official explanation is: fully configured with all versions, apps, input methods, all applications, languages, input methods, and so on. The second half of ENG indicates the engineering machine with the debugging function.

The lunch command prints all the information, as shown in the following table:

Build name

Device

Notes

Full

Emulator

Fully configured with all ages, apps, input methods

Full_maguro

Maguro

Full build running on Galaxy Nexus GSM/HSPA + ("maguro ")

Full_panda

Panda

Full build running on pandabard ("Panda ")

Buildtype

Use

User

Limited access; suited for Production

Userdebug

Like "user" but with root access and debuggability; preferred for debugging

Eng

Development Configuration with additional debugging tools

 

Prepare before Compilation

Because we use ubuntu12.04 to compile Android, Android does not recommend the compilation platform of ubuntu12.04. Some library compatibility issues may cause some errors during the compilation process, we need to make some corrections.

Error message:

g++ selected multilib '32' not installed

Or

<command-line>:0:0: error:"_FORTIFY_SOURCE" redefined [-Werror] <built-in>:0:0: note: this is thelocation of the previous definition cc1plus: all warnings being treated aserrorsmake: ***[out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1

Cause:

In the Android system process, to use the gcc-4.4/g ++-4.4 compiler, while ubuntu12.04 GCC version is 4.6.3

Solution:

Install gcc-4.4

$sudo apt-get install gcc-4.4$sudo apt-get install g++-4.4

Go to the/usr/bin directory, delete the GCC link to the gcc-4.6, and create a link to the newly installed gcc-4.4:

$cd /usr/bin$sudo rm -r gcc$sudo ln -s gcc-4.4 gcc

Verification Result:

$gcc -v$g++ -v

Print its version as gcc-4.4x, G ++-4.4x.

 

Ø compile source code

Enter the following command to start Compilation:

$ make -jn

Here,-JN indicates that n threads are compiled at the same time. Generally, n is twice the CPU core. However, it must also be related to your Ubuntu memory, each thread requires at least 1 GB of memory during compilation. If you do not have much memory, use the make command directly. Otherwise, an error will occur after compilation.

This process takes at least four hours for a virtual machine. For a physical machine, you need to check the configuration. Generally, it takes more than one hour.

Shows the successful compilation result:

Compile the goldfish kernel source code

To compile the Linux source code, you must first specify the GCC cross compiler, we directly use the android built-in arm-eabi-4.4.3 compiler, it is in the working_directory/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin path.

$ ls WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin

Let's compile the following compilation script make_zimage.sh to compile the goldfish kernel:

#!/bin/bashexport PATH=/home/farsight/andorid/android4.0/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATHexport ARCH=armexport SUBARCH=arm export CROSS_COMPILE=arm-eabi-  make goldfish_armv7_defconfig  make

Add executable permissions to make_zimage.sh and execute the compilation script:

$ chmod a+x make_zImage.sh$ ./make_zImage.sh

When we see the following results, the goldfish kernel is compiled:

4. Android compilation process analysis

For details about the android compilation process, refer to the following three blog posts:

Android compilation system (1): http:/blog.csdn.net/mr_raptor/article/details/7539978

Android compilation system (2): http://blog.csdn.net/mr_raptor/article/details/7540066

Android compilation system (III): http:/blog.csdn.net/mr_raptor/article/details/7540730

Follow the steps in Google's compilation:

1> source build/envsetup. sh: Load command

2> lunch: select the target platform compilation Option

3> make: Execute Compilation

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

 

4.1 source build/envsetup. Sh

This command is used to load all the commands used in envsetup. Sh to environment variables. The main Commands are as follows:

Function help () # display help information function check_product () # Check productfunction check_variant () # Check the variable function printconfig () # print the configuration function add_lunch_combo () # Add the lunch project function print_lunch_menu () # print the lunch list function lunch () # configure lunchfunction M () # make from topfunction mm () # make from current directoryfunction Mmm () # Make the supplied Directories

Build/envsetup. sh:

Ü load the function commands used during compilation, such as help, lunch, M, mm, and mmm.

Ü two compilation options are added: Generic-Eng and simulator, which are the default system options.

Ü find the vendor/*/vendorsetup. SH and device/*/vendorsetup. sh. In other words, find vendorsetup in the directory vendor/<vendor directory>/<platform Device directory>/and device/<vendor directory>/<platform Device directory>. sh. If it is found, load and execute it and add the compilation options of the vendor-defined product.

If you want to add your desired device compilation options, you must create a device vendor under the device or vendor directory, and then create a vendorsetup under the device vendor directory. sh file to add your own compilation items.

$mkdir -p device/farsight/fsdevice$touch device/farsight/fsdevice/vendorsetup.sh  $echo "add_lunch_combo fs100-eng" > device/farsight/fsdevice/vendorsetup.sh

Note:

Farsight: vendor name

Fsdevice: Platform device name

Fs100-eng: the custom target product name is fs100, Eng is the compilation target type

The format of all compilation items is device name-compilation target type. The compilation target type is Eng, user, and userdebug. For details, see section 3.1 ).

 

Next, let's verify our results. When we execute source build/envsetup. Sh again in the android directory, we can see the newly added compilation items:

 
4.2 run lunch full-Eng

Of course, we can also directly execute the lunch command and select our compilation items in the pop-up menu, as shown in:

Note: The compilation item we added already exists, but if you select it, an error will occur during compilation because we do not have a configuration file for the compilation item.

The lunch command can export important environment variables with or without parameters, thus affecting the compilation results of the compilation system. The exported variables are as follows (taking lunch full-Eng as an example ):

TARGET_PRODUCT=fullTARGET_BUILD_VARIANT=engTARGET_BUILD_TYPE=release  

 

4.3 run the make command

After entering the make command, we will start compiling the Android system. All makefiles are built through Build/CORE/main. the MK file is organized together. It defines a default goals: droid. When we are in the top directory, hitting make is equivalent to executing make droid.

When make include all files are parsed to all make 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. Among them, the config. mk, envsetup. mk, and product_config.mk files are key files for compiling the user-specified platform system. The android compilation system is complex. For details, refer to the previous blog.

The following are some frequently used commands during compilation:

Source build/envsetup. SH: load the compilation command to generate the compilation option lunch or lunch XXX-yyy: print the compilation option menu or specify the compilation option, xxx indicates the product, and YYY indicates the compilation type make: According to the lunch option, compile the Android system. The final output is: system. IMG, ramdisk. IMG, userdate. imgm: The same as the make command. MM: Compile the target Mmm from the current directory. Specify a directory and only compile the target make Snod under the specified directory: only the content in the out/target/product/XXX/system/directory is packaged to generate system. IMG does not check the dependency make bootimage: only the content in the out/target/product/XXX/root/directory is packaged to generate ramdisk. IMG
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.