Obtain and compile the android source code in Ubuntu 11.04

Source: Internet
Author: User
Tags gnupg gpg valgrind

In the past two days, we have started to prepare the source code compilation. In this case, we will record the process so that we can easily back up the source code and hope it will be helpful to the later users.

Attention: the environment in this article is to obtain and compile the source code of Android 2.3.3 under Ubuntu 11.04,

 

The process reference easwy's blog: http://www.2cto.com/kf/201111/110741.html

And Google official website http://source.android.com/source/downloading.html.

 

The requirements on the official website are:

In general you will need:


Python 2.4 -- 2.7, which you can download from python.org.

• JDK 6 if you wish to build gingerbread or newer; JDK 5 for froyo or older. You can download both from java.sun.com.

• Git 1.5.4 or newer. You can find it at git-scm.com.

• (Optional) valgrind, a tool that will help you find memory leaks, stack rollback uption, Array Bounds overflows, etc. Download from valgrind.org.

In addition: 6 GB or more disk space, dependent Deb package: Flex, Bison, gperf, libsdl-Dev, libesd0-dev, libwxgtk2.6-Dev, Build-essential, zip, curl

I. Preparations before downloading

First, after preparing the required disk space, install the required development kits and execute the following commands on the terminal:

$ Sudo apt-Get install Git-core GnuPG flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

Here, you need to pay attention to two points: 1. libsdl version 1.2; 2. zlib1g-dev do not see the error is 1 rather than l, of course, not the hands of the Tx there is no such problem.

Then you need to install the Java environment and view the version directly on the terminal:

Wayne @ Ubuntu :~ $ Java-version

The program "Java" is included in the following software packages:

* Gcj-4.4-jre-headless

* Gcj-4.5-jre-headless

* Openjdk-6-jre-headless

Please try: sudo apt-Get install <selected software package>

Input: sudo apt-Get install openjdk-6-jre-headless, installation is OK, and then view the version:

Wayne @ Ubuntu :~ $ Java-version

Java version "1.6.0 _ 22"

Openjdk Runtime Environment (icedtea6 1.10.2) (6b22-1.10.2-0ubuntu1 ~ 11.04.1)

Openjdk server VM (build 0-b11, mixed mode)

JDK is installed.

Ii. Download source code

Now we have prepared the environment required for Android source code development (no error). The process of downloading the source code is very huge because the android source code needs to be obtained in two parts: Android source code and kernel. I don't need the source code of the kernel for the time being, so here I only download the source code.

1. Create a new folder to store the android directory and initialize the repo:

Wayne @ Ubuntu :~ $ Mkdir android

Wayne @ Ubuntu :~ $ CD android

Wayne @ Ubuntu :~ /Android $ mkdir Bin

Wayne @ Ubuntu :~ /Android $ CD Bin

Wayne @ Ubuntu :~ /Android/bin $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> Repo

% Total % received % xferd average speed time Time Current

Dload upload total spent left speed

100 19731 100 19731 0 0 14034 0 0:00:01 --: -- 17157

 

Here, a few months ago:

Wayne @ Ubuntu :~ /Android/bin $ curl http://android.git.kernel.org/repo> Repo

% Total % received % xferd average speed time Time Current

Dload upload total spent left speed

100 244 100 244 0 0 75 0 0:00:03 --: -- 976

Then, the following error occurs during subsequent code initialization:

./Bin/repo: Row 1: Unexpected syntax error near the symbol 'newline'

./Bin/repo: Row 1: '<! Doctype HTML public "-// IETF // dtd html 2.0 // en">'

2. continue now. Create and store the source code directory and initialize the required Android source code version. Run the following command on the terminal:

Wayne @ Ubuntu :~ /Android/bin $ sudo chmod A + x Repo

Wayne @ Ubuntu :~ /Android/bin $ cd

Wayne @ Ubuntu :~ $ CD Android/source/

Wayne @ Ubuntu :~ /Android/source $ ../bin/repo init-u https://android.googlesource.com/platform/manifest-B android-2.3.3_r1

GPG: the key ring '/home/Wayne/. repoconfig/GnuPG/secring. gpg' has been created.

GPG: the key ring '/home/Wayne/. repoconfig/GnuPG/pubring. gpg' has been created.

GPG:/home/Wayne/. repoconfig/GnuPG/trustdb. GPG: Build a trust Database

GPG: Key 920f5c65: Public Key "Repo maintainer <repo@android.kernel.org>" imported

GPG: Total number of processed items: 1

GPG: imported: 1

 

Get https://android.googlesource.com/tools/repo

Remote: counting objects: 1414, done

Remote: Finding sources: 100% (78/78)

Remote: Total 1414 (delta 917), reused 1414 (delta 917)

Grouping objects: 100% (1414/1414), 429.88 kib | 169 kib/s, done.

Resolving deltas: 100% (917/917), done.

From https://android.googlesource.com/tools/repo

* [New branch] Maint-> origin/Maint

* [New branch] Master-> origin/Master

* [New branch] stable-> origin/stable

...Www.2cto.com

In this case, you are required to enter the user name and email address.

After initialization, the following error occurs:

Repo initialized in/home/Wayne/Android/source

Now you can download the SDK after initialization. Run the following command on the terminal to download the SDK:

Wayne @ Ubuntu :~ /Android/source $ ../bin/repo sync

It takes a long time to download all the source code, and now it is going through a long wait ......

During the process, you may encounter errors and interruptions:

Error: Exited sync due to fetch errors

If you encounter these problems, re-execute ../bin/repo sync and then OK.

Ii. source code compilation

After the synchronization is complete, go to the android directory and use the make command to compile it. You will find an error.

The specific error message depends on the development environment under your installed ubuntu.

Install the following software in sequence. If the software has been installed, it will be skipped automatically.

Sudo apt-Get install zlib1g-dev

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.

 

If JDK is not installed on your local machine, make still reports an error.

You can download the jdk-6u16-linux-i586.bin file from the sun official website and install it, but because the download from sun was too slow that day, I used the new install software tool, installed the default-JDK instead.

Configure the java_home and PATH environment variables. Here I add all the variables to the end of/etc/profile, and then source/etc/profile, as shown below:

 

 Java_home =/usr/local/src/jdk_xxx

Path = $ path: $ java_home/bin:/usr/local/src/android-sdk-linux_x86-XXX/tools :~ /Bin

 

You can use echo $ java_home and echo $ path to perform the test. If you use Java-version, you will be prompted that the test is successful as follows:

 

Java version "XXXX"

Java (TM) se Runtime Environment (build XXX)

Java hotspot (TM) Client VM (build XXX, mixed mode, sharing)

 

After the above solution is completed, compile the complete project with make:

(If your make directory is ~ /Android) under./out/target/product/generic/, there will be several image files required, as shown below:

 

System. img

Ramdisk. img
Userdata. img

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-XXX in the system, This SDK for (may change later, just for reference):

 

Http://developer.android.com/sdk/index.html(Windows, Linux, and Mac are all here)

 

I decompress it to/usr/local/src/and add the/usr/local/src/android-sdk-linux_x86-XXX/tools directory to the system variable path.

Add the path

Path = $ path: $ home/Android/out/host/linux-x86/bin

My $ home is/home/XXX/

 

Next, we need to load the android image file to emulator so that emulator can see the actual running effect of Android. We need to add the system variable android_product_out:

 

Android_product_out = $ home/Android/out/target/product/generic
Export android_product_out

 

 

Then source it.

 

Enter the simulator directory and start the simulator.

 

CD $ home/Android/out/target/product/generic
Emulator-image system. IMG-data userdata. IMG-ramdisk. img

 

I use vmbox virtual machine, UBUNTU 11.04, 16 GB virtual hard disk, MB memory allocation.

Host Machine with 2 GB memory, 2, 33 GHz intel core2 duo CPU

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.