Full process of compiling Android source code in Ubuntu 8.04

Source: Internet
Author: User

Author: Sun Dongfeng

 

1. Obtain the Android source code

Git is an open source distributed version control software developed by Linux Torvalds to help manage Linux kernel development. It is different from a centralized version control system such as Subversion and CVS. In a centralized version control system, there is only one warehouse (Repository) and many Working directories (Working Copy ), in distributed version control systems such as Git (other major distributed version control systems include BitKeeper, Mercurial, GNU Arch, Bazaar, Darcs, SVK, and Monotone ), each working directory contains a complete repository that supports offline work. Local submission can be submitted to the server later.

 

Because Android is composed of multiple projects, such as Kernel, Dalvik, Bionic, Prebuilt, and build, It is very troublesome to use Git to obtain them one by one, therefore, the Android project has compiled a Python script named Repo to manage the repositories of these projects in a unified manner, making the project acquisition easier.

 

To install Git on Ubuntu 8.04, you only need to set the correct update source and use apt-get. apt-get is a Linux Command, it is mainly used to search, install, upgrade, and uninstall software or operating systems from software warehouses on the Internet.

The apt-get command generally requires the root permission for execution, so it is generally followed by The sudo command.

 

Sudo apt-get install git-core curl

 

This command installs git-core and curl from the software repository on the Internet.

 

Curl is a File Transfer tool that uses the URL syntax to work in the command line mode. It supports many protocols, including FTP, FTPS, HTTP, HTTPS, and TELENT, we need to install it to obtain the Repo script file from the network.

 

Curl http://android.git.kernel.org/repo> ~ /Bin/repo

 

This command downloads the repo script file to the/bin directory of the current home directory and saves it in the file repo.

 

Finally, we need to grant the repo file executable permission.

 

Chmod a + x ~ /Bin/repo

 

Next, we can use the repo script, Git, and curl software to obtain the Android source code :)

 

First, create a directory, such ~ /Android.

Run the following command to obtain the source code:

 

Repo init-u git: // android.git.kernel.org/platform/manifest.git

 

This process will take a long time (I downloaded it for one day). After the download is complete, I will see a prompt such as repo initialized in/android, indicating that the local version library has been initialized, and contains the latest sourcecode.

 

If we want to use the code of a branch version instead of the main line code, we need to use the-B parameter to specify the branch name, for example:

 

Repo init-u git: // android.git.kernel.org/platform/manifest.git-B cupcake

 

If we only want to get the code of a project, such as kernel/common, we do not need a repo script. We can directly use the Git tool. If we carefully study the repo script, we will find that, the repo script actually organizes Git tools to get various projects and organize them into the same Project Android.

 

Git clone git: // android.git.kernel.org/kernel/common.git

 

We obtained various projects using the repo script above, and then we need to synchronize the entire Android code tree to the local, as shown below:

 

Repo sync project1 project2...

 

I use the repo sync command to directly synchronize all projects to the local device.

 

Ii. source code compilation

 

After the synchronization is complete, go to the Android directory and use the make command to compile the SDK. the following error message is displayed:

 

Host C: libneo_cgi <= external/clearsilver/cgi. c
External/clearsilver/cgi. c: 22: 18: error: zlib. h: No such file or directory

 

This error is because we lack the zlib1g-dev and need to install it from the software repository using the apt-get command, as shown below:

 

Sudo apt-get install zlib1g-dev

 

Similarly, we also need to install the following software in sequence.

 

Sudo apt-get install flex

Sudo apt-get install bison

Sudo apt-get install gperf

Sudo apt-get install libsdl-dev

Sudo apt-get install libesd0-dev

Sudo apt-get install libncurses5-dev

Sudo apt-get install libx11-dev

 

After all the above software is installed, run the make command to re-compile the Android source code.

 

At this time, you will find many errors that cannot be compiled by java files, open the Android source code. We can see that there are many java source files in android/dalvik/libcore/dom/src/test/java/org/w3c/domts, this means that JDK must be installed before compiling Android.

First download the jdk-6u16-linux-i586.bin file from the sun official website and install it.

 

In Ubuntu 8.04, the/etc/profile file is a global environment variable configuration file, which applies to all shells. When we log on to the Linux system, first start the/etc/profile file, and then start ~ /. Bash_profile ,~ /. Bash_login or ~ /. One of the profile files is executed in the same order as the preceding sorting. If ~ /. If the bash_profile file exists, it is generally executed ~ /. Bashrc file.

So we only need to put the JDK directory in/etc/profile, as shown below:

 

JAVA_HOME =/usr/local/src/jdk1.6.0 _ 16

PATH = $ PATH: $ JAVA_HOME/bin:/usr/local/src/android-sdk-linux_x86-1.1_r1/tools :~ /Bin

 

Restart the machine and enter the java-version command. The following message indicates that the configuration is successful:

 

Java version "1.6.0 _ 16"

Java (TM) SE Runtime Environment (build 1.6.0 _ 16-b01)

Java HotSpot (TM) Client VM (build 14.2-b01, mixed mode, sharing)

 

After the entire project is compiled, the following prompt appears:


Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system. img
Install system fs image: out/target/product/generic/system. img
Target ram disk: out/target/product/generic/ramdisk. img
Target userdata fs image: out/target/product/generic/userdata. img
Installed file list: out/target/product/generic/installed-files.txt
Root @ dfsun2009-desktop:/bin/android #

 

Iii. Run the source code

 

After compiling the entire project, if we need to watch the compiled running effect, then we need to install the simulator android-sdk-linux_x86-1.1_r1 in the system, This SDK is:

 

Http://dl.google.com/android/android-sdk-linux_x86-1.1_r1.zip: linux
MacOS: http://dl.google.com/android/android-sdk-mac_x86-1.1_r1.zip
Windows: http://dl.google.com/android/android-sdk-windows-1.1_r1.zip

 

After decompression, add the/usr/local/src/android-sdk-linux_x86-1.1_r1/tools directory to the system environment variable/etc/profile.

 

Then find the compiled android directory file out, we found that many applications in android/out/host/linux-x86/bin, these applications are the basis for android to run, therefore, we need to add this directory to the system PATH at $ HOME /. add the following content to the profile file:

 

PATH = "$ PATH: $ HOME/android/out/host/linux-x86/bin"

 

Next, we need to load the android image file to emulator so that emulator can see the actual running effect of android. Add the following content to the $ HOME/. profile file:

 

ANDROID_PRODUCT_OUT = $ HOME/android/out/target/product/generic
Export ANDROID_PRODUCT_OUT

 

Then restart the machine.

 

Enter the simulator directory and start the simulator.

 

Cd $ HOME/android/out/target/product/generic
Emulator-image system. img-data userdata. img-ramdisk. img

 

 

Summarize the key points in the installation process:

1: JDK version is required

2: Use the following command to ensure that all required software is correctly installed.

Sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential python valgrind curl git

3: the memory and virtual memory are above 2 GB. You can use the command line free-m to check whether the memory is sufficient. If the memory is not enough, the terminal stops.

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.