Download and compile the source code and kernel of android4.0

Source: Internet
Author: User
Tags gnupg

Download the android source code and compile it. Problems:

After the release of the latest android4.0 source code, I believe many people are eager to try it like me. In fact, the download and compilation of 4.0 code are similar to those of previous versions, but there are some minor differences, write it down for reference by beginners who do not know the truth

First of all, in the development environment, Google recommends that you use ubuntu10.0.4 and preferably 64-bit. Since it is for work and study, follow the official requirements as much as possible.

Python 2.5 -- 2.7 ubuntu10.0.4 has been installed by default, so you do not need to install it. You need to install it in other environments.

JDK 6 compiling 4.0 requires JDK 6 and JDK 5 for SDK Compilation

Git 1.7 or newer

If your Ubuntu is 32-bit, follow these steps before the source code is downloaded and compiled: (Note: You need to change the following before. You don't need it now. You can compile it directly, google seems to have done 32 bits, and 64 bits can be compiled)

After downloading the source code, modify the following four files: external/clearsilver/cgi/Android. mk.
External/clearsilver/Java-JNI/Android. mk
External/clearsilver/util/Android. mk
External/clearsilver/CS/Android. mk

Set local_cflags + =-M64
Local_ldflags + =-M64

Change to local_cflags + =-M32
Local_ldflags + =-M32

In build/CORE/Main. mk

Find ifneq (64, $ (findstring 64, $ (build_arch )))

Change it to ifneq (i686, $ (findstring i686, $ (build_arch )))

If you install Ubuntu with the latest 11.04 header, a header file loss error may occur at the end of the compilation due to the kernel version bug. For example:, please fix it as follows:

Repo download platform/external/qemu 22776/1 if you are 10.0.4, do not do anything redundant. If you fix it, the compiled version may fail to enter the system due to the black screen. Remember!

The compiling environment is different, and the problems you encounter may be strange. If your compilation has a problem, please develop the habit of Google and Baidu.

1: JDK is relatively simple to install.

2: Install the dependency Library:

64-bit:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \  libxml2-utils xsltproc
32-bit
$ 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

On Ubuntu 10.10:

    $ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

On Ubuntu 11.10:

    $ sudo apt-get install libx11-dev:i386
3: Download Repo
$ mkdir ~/bin $ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo $ chmod a+x ~/bin/repo

4: Create the source code directory:

$ mkdir ANDROID_SOURCE
$ cd ANDROID_SOURCE
5: Get the android source code version on git
$ repo init -u https://android.googlesource.com/platform/manifest
Download the latest version.
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1
In this case, you need to enter the user name and email
 
After entering the information, run the synchronization command.
6: Download source code
$ repo sync
Add parameter:-JX indicates how many threads are enabled to download the source code.
Source code + repo around 13 Gb (because repo will automatically execute the check out command)
If an error occurs in the middle or the network is unstable, You Can reinitialize the repo and use the same email to synchronize the local git Library and the GIT library on the server.
Compile source codeAfter downloading the source code, go to the source code home directory.
1: run:
$ source build/envsetup.sh
The Souce command executes the envsetup file under the build directory of the source code package.
 
We can see that this file defines a lot of functions for compilation.
function help()function get_abs_build_var()function get_build_var()function check_product()function check_variant()function setpaths()function printconfig()function set_stuff_for_environment()function set_sequence_number()function settitle()function choosetype()function chooseproduct()function choosevariant()function tapas()function choosecombo()function print_lunch_menu()function lunch()function gettopfunction m()function findmakefile()function mm()function mmm()function croot()function pid()function gdbclient()function jgrep()function cgrep()function resgrep()function getprebuiltfunction tracedmdump()function runhat()function getbugreports()function startviewserver()function stopviewserver()function isviewserverstarted()function smoketest()function runtest()function runtest_py()function godir ()
2: select a target
$ lunch full-eng
 
We compile and run it in the simulator, so select "full ".
 
We select the maximum permission, that is, the version after root, so select Eng
3: Compile source code
$ make -j4
About 3 hours
After compilation, the out folder is generated in the source code directory.
 
Okay, you can check whether the following compiled source code is running properly.
$ emulator
If the command cannot be found, initialize the environment.
$ source build/envsetup.sh$ lunch full-eng
 
 
The following error may occur during the download process:
 
 
  1. Exception in thread-3:
  2. Traceback (most recent call last ):
  3. File "/usr/lib/python2.6/threading. py", line 532, in _ bootstrap_inner
  4. Self. Run ()
  5. File "/usr/lib/python2.6/threading. py", line 484, in run
  6. Self. _ target (* Self. _ ARGs, ** self. _ kwargs)
  7. File "/home/haili/android-4.0.4_r1.2/. repo/subcmds/Sync. py", line 200, in _ fetchhelper
  8. Clone_bundle = not opt. no_clone_bundle)
  9. File "/home/haili/android-4.0.4_r1.2/. repo/Project. py", line 978, in sync_networkhalf
  10. And self. _ applyclonebundle (initial = is_new, quiet = quiet ):
  11. File "/home/haili/android-4.0.4_r1.2/. repo/Project. py", line 1519, in _ applyclonebundle
  12. Exist_dst = self. _ fetchbundle (bundle_url, bundle_tmp, bundle_dst, quiet)
  13. File "/home/haili/android-4.0.4_r1.2/. repo/Project. py", line 1583, in _ fetchbundle
  14. Raise downloaderror ('% s: % s' % (req. get_host (), STR (E )))
  15. Downloaderror: android.googlesource.com: <urlopen error [errno 110] connection timed out>
  16. ...
Exception in thread-3: traceback (most recent call last): file "/usr/lib/python2.6/threading. PY ", line 532, in _ bootstrap_inner self. run () file "/usr/lib/python2.6/threading. PY ", line 484, in run self. _ target (* self. _ ARGs, ** self. _ kwargs) file "/home/haili/android-4.0.4_r1.2 /. repo/repo/subcmds/Sync. PY ", line 200, in _ fetchhelper clone_bundle = not opt. no_clone_bundle) file "/home/haili/android-4.0.4_r1.2 /. repo/repo/project. PY ", line 978, in sync_networkhalf and self. _ applyclonebundle (initial = is_new, quiet = quiet): file "/home/haili/android-4.0.4_r1.2 /. repo/repo/project. PY ", line 1519, in _ applyclonebundle exist_dst = self. _ fetchbundle (bundle_url, bundle_tmp, bundle_dst, quiet) file "/home/haili/android-4.0.4_r1.2 /. repo/repo/project. PY ", line 1583, in _ fetchbundle raise downloaderror ('% s: % s' % (req. get_host (), STR (E) downloaderror: android.googlesource.com: <urlopen error [errno 110] connection timed out>...

This error is inexplicable. python is correctly installed and the version is required. In fact, the official website (http://source.android.com/source/downloading.html) has a paragraph description, if seriously executed can solve.

1. log on to https://android.googlesource.com/new-passwordin the browser and use the gmailaccount number to renew it;

2. Click "Allow access" on the webpage to obtain the following information:

  1. Machine android.googlesource.com login Git-<username> .gmail.com password <password>
  2. Machine android-review.googlesource.com login Git-<username> .gmail.com password <password>
Machine android.googlesource.com login Git-<username> .gmail.com password <password> machine android-review.googlesource.com login Git-<username> .gmail.com password <password>

.

3. append the above information (<username> and <password> with your own real information) ~ /. The End Of The netrc file;

4. Uri changed to https://android.googlesource.com//Platform/manifest ("/a" is added in the middle ").

Then follow the normal steps described on the official website to pull down the android source code. The official statement is: Because access is basically anonymous, in order to prevent too many connections, the number of connections to the same IP address is limited. It seems to be using a Gmail account for authentication.

In this case, you will often encounter this problem when downloading from the company network or using virtual machines.

Compilation problems:

The problem is as follows:

Install: Out/host/linux-x86/framework/droiddoc. jartarget generated: libclearsilver-JNI <= out/host/common/obj/java_libraries/clearsilver_intermediates/javalib. jarhost C: libclearsilver-JNI <= external/clearsilver/Java-JNI/j_neo_util.cin file encoded from/usr/include/features. h: 378, from/usr/include/string. h: 26, from external/clearsilver/Java-JNI/j_neo_util.c: 1:/usr/include/GNU/stubs. h: 9: 27: Error: GNU/stubs-64.h: No file or directory make: *** [out/host/linux-x86/obj/shared_libraries/libclearsilver-jni_intermediates/j_neo_util.o] Error 1

Solution:

sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6

Download Android kernel and compile it:

Step 1: Download the goldfish source code

Create a kernel folder under the root directory of the android source code

  1. $ Mkdir Kernel
  2. $ CD Kernel

$ Mkdir <br/> kernel <br/> $ CD KernelDownload source code:

  1. $ Git clone http://android.googlesource.com/kernel/goldfish.git

$ Git <br/> clone http://android.googlesource.com/kernel/goldfish.git
The download is completed as follows:

A goldfish folder is generated under the kernel directory. Go to this directory:

  1. $ CD goldfish

$ CD <br/> goldfish
There is a hidden directory under this directory. Git, through

  1. $ LS-Al

$ Ls <br/>-Al
You can see this directory:

View All branches:

  1. Git branch-

Git <br/> branch-For example:

Check out:

  1. $ Git checkout remotes/ORIGIN/Android-goldfish-2.6.29

$ Git <br/> checkout remotes/ORIGIN/Android-goldfish-2.6.29

At this point, you will see many files in the goldfish directory.

  1. $ Ls

$ Ls

At this time, the goldfish source code has been compiled.

Step 2: Compile goldfish

Export the cross-compilation tool directory to the $ PATH environment variable.

  1. Export Path = $ path :~ /Working_directory/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin

Export </P> <p> Path = $ path :~ /Working_directory/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin <br/>
We will use the cross compiler under the above directoryArm-Eabi-Gcc

Then open the MAKEFILE file with gedit in the glodfish directory and find the two lines of text:

 # Arch

? = (Subarch)

# Cross_compile ? =
To:
Arch? = Arm

Cross_compile? = Arm-Eabi-

  1. $ Gedit makefile

$ Gedit <br/> makefile
Note: arth? = Arm. Do not have spaces behind the arm. Otherwise, the following error may occur:
Make:.../kernel/goldfish/ARCH/arm: is a directory. Stop.
I wasted a few hours.

The purpose of the above operations is to specify the architecture and cross compiler of the target device. In fact, the following commands can be used to complete the operation:

  1. $ Export arch = arm
  2. $ Export subarch = arm
  3. $ Export cross_compile = arm-Eabi-

$ <Br/> export arch = arm <br/> $ export subarch = arm <br/> $ export cross_compile = arm-Eabi-

To ensure that the environment parameters are correct, run the following two commands. Otherwise, the simulator may fail to be started. (Note: The following two commands are executed in the root directory of the android source code)

  1. $ Source build/envsetup. Sh // This command is missing and may cause compilation failure
  2. $ Lunch full-Eng // if this command is missing, the module may fail to be started. The system reports that AVD cannot be found and asks you to create an AVD.

$ <Br/> source build/envsetup. sh // if this command is missing, the compilation may fail. <br/> $ lunch full-Eng // if this command is missing, the module may fail to be started, the system reports that AVD cannot be found and asks you to create an AVD.
Close gedit and start make. Execute the following command:

  1. $ Make goldfish_armv7_defconfig
  2. $ Make

$ Make <br/> goldfish_armv7_defconfig <br/> $ make <br/>Note: The configuration with $ make goldfish_defconfig can also be compiled, and the simulator can also be started, but it cannot be displayed on the android machine, and $ ADB shell cannot be connected, this is because of the configuration file goldfish_defconfig.

Tip:
$ Make goldfish_armv7_defconfig command means to copy the kconfig configuration content in the worker file under the working_directory/kernel/goldfish/ARCH/ARM/configs/directory to the working_directory/kernel/goldfish/directory. in the config file ,. the config file is a hidden directory that stores the configuration of the kconfig file in each directory.
The final result is shown in:

This indicates that the compilation is successful.

  1. $ Ls ARCH/ARM/boot/

$ <Br/> ls ARCH/ARM/boot/<br/>The zimage file is displayed.

Step 3: Start the compiled kernel in the simulator
 
Run the following command:

  1. $ Export Path = $ path :~ /Working_directory/out/host/linux-x86/bin
  2. $ Export android_product_out = ~ /Working_directory/out/target/product/generic
  3. $ Emulator-kernel ~ /Working_directory/kernel/goldfish/ARCH/ARM/boot/zimage &

$ <Br/> export Path = $ path :~ /Working_directory/out/host/linux-x86/bin <br/> $ export <br/> android_product_out = ~ /Working_directory/out/target/product/generic <br/> $ emulator-kernel <br/> ~ /Working_directory/kernel/goldfish/ARCH/ARM/boot/zimage & <br/>Simulator startup interface:

Go to the simulator to view the version information from the settings:

We can see that the current Android version is 4.0.1 and the kernel version is 2.6.29.

You can also view the kernel version information through the ADB shell, such:

  1. $ ADB Shell
  2. # Cd proc
  3. # Cat version

$ Adb <br/> shell <br/> # cd proc <br/> # Cat version <br/>

Complete!

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.