Compile android source code 4.0.3 in Ubuntu11.10

Source: Internet
Author: User
In the previous articles, I introduced the android source code download method under UbuntuLinux, the Eclipse development environment for android under Ubuntu11.10, and some problems encountered during the configuration process, this article will continue to introduce the android source code 4.0.3 compiler under Ubuntu11.10... in previous articles, I introduced some problems encountered in the configuration process, including "how to download the android source code for Ubuntu Linux", "how to configure the Eclipse development environment for android under Ubuntu11.10, this article continues to introduce how to compile android 4.0.3 in Ubuntu11.10.
 
1. initialize the compiling environment
 
Software Requirements:
Python2.5-2.7, which can be downloaded at http://www.python.org/download/( with Ubuntu11.10 ).
JDK6: compile Gingerbread or update version; JDK5: compile Froyo or earlier versions. You can download the SDK at http://java.sun.com/javase/downloads/or through the ubuntusoftware center.
You can download Git1.7 or the latest version at http://git-scm.com/download, or directly download sudo apt-get install git under the latest version.
 
Install JDK
JDK installation in Ubuntu is relatively simple. you can search for the installation in the software center or install it in the following ways:
Install Java 6:
 
1 $ sudo add-apt-repository "deb http://archive.canonical.com/lucid partner"
 
2 $ sudo apt-get update
 
3 $ sudo apt-get install sun-java6-jdk
 
Install Java 5:
 
1 $ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hard main multiverse"
 
2 $ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hard-updates main multiverse"
 
3 $ sudo apt-get update
 
4 $ sudo apt-get install sun-java5-jdk
 
Install the required software package for compilation:
 
1 $ sudo ln-s/usr/lib/i386-linux-gnu/libX11.so. 6/usr/lib/i386-linux-gnu/libX11.so
 
2
 
3 $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils xsltproc
 
Configure USB access permissions
In GNU/Linux systems (especially in Ubuntu systems), by default, normal users cannot directly access USB devices. Therefore, some system configurations are required.
 
Create a new configuration file/etc/udev/rules. d/51-android.rules as a super user and copy the following content to the new configuration file:
 
01 # adb protocol on passion (Nexus One)
 
02 SUBSYSTEM = "usb", ATTR {idVendor} = "18d1", ATTR {idProduct} = "4e12", MODE = "0600", OWNER =" "
 
03 # fastboot protocol on passion (Nexus One)
 
04 SUBSYSTEM = "usb", ATTR {idVendor} = "0bb4", ATTR {idProduct} = "0fff", MODE = "0600", OWNER =" "
 
05 # adb protocol on crespo/crespo4g (Nexus S)
 
06 SUBSYSTEM = "usb", ATTR {idVendor} = "18d1", ATTR {idProduct} = "4e22", MODE = "0600", OWNER =" "
 
07 # fastboot protocol on crespo/crespo4g (Nexus S)
 
08 SUBSYSTEM = "usb", ATTR {idVendor} = "18d1", ATTR {idProduct} = "4e20", MODE = "0600", OWNER =" "
 
09 # adb protocol on stingray/wingray (Xoom)
 
10 SUBSYSTEM = "usb", ATTR {idVendor} = "22b8", ATTR {idProduct} = "70a9", MODE = "0600", OWNER =" "
 
11 # fastboot protocol on stingray/wingray (Xoom)
 
12 SUBSYSTEM = "usb", ATTR {idVendor} = "18d1", ATTR {idProduct} = "708c", MODE = "0600", OWNER =" "
 
13 # adb protocol on maguro/toro (Galaxy Nexus)
 
14 SUBSYSTEM = "usb", ATTR {idVendor} = "04e8", ATTR {idProduct} = "6860", MODE = "0600", OWNER =" "
 
15 # fastboot protocol on maguro/toro (Galaxy Nexus)
 
16 SUBSYSTEM = "usb", ATTR {idVendor} = "18d1", ATTR {idProduct} = "4e30", MODE = "0600", OWNER =" "
 
17 # adb protocol on panda (pandabard)
 
18 SUBSYSTEM = "usb", ATTR {idVendor} = "0451", ATTR {idProduct} = "d101", MODE = "0600", OWNER =" "
 
19 # fastboot protocol on panda (PandaBoard)
 
20 SUBSYSTEM = "usb", ATTR {idVendor} = "0451", ATTR {idProduct} = "d022", MODE = "0600", OWNER =" "
 
In addition
 
1" "
 
Change to user name, for example, "Taskiller ".
 
2. configure ccache
Ccache (abbreviation of "compiler cache") is a compiler cache. this tool caches the compiled information and uses the cached information in specific parts of the compilation, such as header files, this saves the time required to parse the information using cpp. If you compile the file in listing 2 and assume that foobar. h contains references to other header files, ccache replaces the include declaration with the cpp-parsed version of that file. Ccache only copies the final text to the file so that it can be compiled immediately, instead of actually reading, understanding, and interpreting its content.
 
This step is optional. I didn't configure ccache during compilation, and it took Nima at least six hours for the final compilation. although I haven't tried to configure the compilation speed after ccache, we recommend that you configure it to save compilation time. The configuration method is as follows:
Open. bashrc in the user directory, add the following statement to the end of the file, and save and exit:
 
1 export USE_CCACHE = 1
 
By default, the cache is saved in ~ /. In the ccache Directory, if the main directory is in NFS or another non-local file system, add the following statement to. bashrc, save it, and exit:
 
1 export CCACHE_DIR =
 
Set
 
1 Change to the location of the cache directory.
 
The recommended cache directory is 50-100 GB. run the following command on the command line:
 
1 prebuilt/linux-x86/ccache-M 50G
 
This setting will be saved to CCACHE_DIR, and this command is long-term and will not expire due to system restart.
 
3. use a lower version of gcc and g ++
 
The gcc and g ++ versions of Ubuntu11.10 are 4.6. some errors may occur when android is compiled using this version, such:
 
1 host Prebuilt: monkeyrunner (out/host/linux-x86/obj/EXECUTABLES/monkeyrunner_intermediates/monkeyrunner)
 
2 host C ++: obbtool <= frameworks/base/tools/obbtool/Main. cpp
 
3 <命令行> : 0: 0: Error: "_ FORTIFY_SOURCE" redefinition [-Werror]
 
4 : 0: 0: Note: This is the previously defined position.
 
5 cc1plus: all warnings are considered as errors
 
There are articles on modifying build/core/combo/HOST_linux-x86.mk files that will
 
1 HOST_GLOBAL_CFLAGS + =-D_FORTIFY_SOURCE = 0
 
Modify
 
1 HOST_GLOBAL_CFLAGS + =-U_FORTIFY_SOURCE-D_FORTIFY_SOURCE = 0
 
Although this method can solve this problem, it will also lead to new problems and continue to be modified, which is very troublesome and will damage the native status of the android source code. However, if gcc and g ++ of version 4.4 are used, the following error will not occur:
 
Through the gcc-v command, we can find that the gcc Library is under the/usr/lib/gcc/i686-linux-gnu directory, which contains the gcc library of various versions supported by the current system. There is no 4.4 Directory in this directory before gcc 4.4 is installed. after gcc 4.4 is installed, there will be an additional 4.4 Directory in this directory, and there will be various library files under this 4.4 Directory.
 
The best way to install gcc 4.4 in ubuntu 32bit system is to use only the following two commands without other commands. otherwise, errors may occur during compilation.
 
1 $ sudo apt-get install gcc-4.4
 
2 $ sudo apt-get install g ++-4.4
 
After installation, go to the/usr/bin directory.
 
1 $ ls-l gcc *
 
The following results are displayed.
 
Lrwxrwxrwx 1 root 7 2011-10-29 gcc-> gcc-4.6
-Rwxr-xr-x 1 root 224544 gcc-4.4
-Rwxr-xr-x 1 root 302104 gcc-4.6
 
Find that gcc is linked to the gcc-4.6 and you need to link it to the gcc-4.4 as follows:
 
1 $ sudo mv gcc. bak
 
2 $ sudo ln-s gcc-4.4 gcc
 
Similarly, make the same changes to g ++:
 
1 $ ls-l g ++ *
 
Lrwxrwxrwx 1 root 7g ++-> g ++-4.6
-Rwxr-xr-x 1 root 228640g ++-4.4
-Rwxr-xr-x 1 root 306200g ++-4.6
 
You need to change the g ++ link to g ++-4.4:
 
1 $ sudo mv g ++. bak
 
2 $ sudo ln-s g ++-4.4g ++
 
Check the gcc and g ++ versions:
Gcc-v
G ++-v
Gcc version 4.4.6 is displayed, indicating that gcc 4.4 is successfully installed.
 
4. Compile the android source code.
 
Go to the source code directory. The directory is/home/tasiller/android/source. Use the envsetup. sh script to initialize the installation environment. The following code is available:
 
1 $ source build/envsetup. sh
 
Or
 
1 $. build/envsetup. sh
 
Note: There is a space behind it.
 
Then, select the target to be compiled:
 
1 $ lunch full-eng
 
Then the source code is compiled using the make command:
 
1 $ make-j4
 
Here-j4 indicates that four threads are used for compilation, and 4 indicates the number of threads. you can set it according to your own machine (for example, if the machine is a single-CPU dual-core processor, it can be set to-j2 or-j4, that is, this number is twice the total number of CPU cores or the total number of kernels .)
 
Then there is a long wait...
 
After compilation, you can see the compiled ramdisk. img, system. img, and userdata. img in the out/target/product/generic/directory of the source code directory.
 
If not stated, the articles on this site are original articles of Taskiller
 
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.