Ubuntu 10.04 compiling Android 2.1 source code

Source: Internet
Author: User

Preface

This article describes how to build a development environment based on the official Google Android 2.1-r2 source code from scratch, including how to download the source code, compile the source code, and run the compiled image in the simulator. In this article, the development machine is based on Ubuntu 10.04 and is also applicable to other versions of Ubuntu.

2. Download the JDK 1.5.

Compiling Android source code requires JDK 1.6 (mainly javadoc), which is incompatible with version. JDK1.5 is no longer supported, and its final version is JDK 5.0 Update 22.

You can download it from the Sun Official Website:

Http://java.sun.com/javase/downloads/5u22/jdk

Select the platform Linux and select "agree to the license agreement:

Click Continue, there are two downloads in the pop-up page, select the first jdk-1_5_0_22-linux-i586.bin download:

3. Deploy JDK 1.5

3.1 decompress JDK

The following commands are executed on the root account. sudo may be required for non-root accounts to execute some commands.

Place the jdk-1_5_0_22-linux-i586.bin in the root directory. Enter this directory:

Cd ~

Then grant the executable attributes to the bin file:

Chmod + x jdk-1_5_0_22-linux-i586.bin

Then run the installation (Note that there is ./):

/Jdk-1_5_0_22-linux-i586.bin

Skip protocol reading.

Last line:

Do you agree to the above license terms? [Yes or no]

Type yes and press enter to start decompression. By default, it will be decompressed to the jdk1.5.0 _ 22 directory under the current directory (here is ~ /Jdk1.5.0 _ 22 ).

3.2 JDK version Switch

If you need to use JDK1.6 for application development at the same time, JDK1.5 and JDK1.6 will exist in the system at the same time. Therefore, you need to switch between different versions. If JDK 1.5 is not used, skip to Section 3.3 after completing the settings.

Use the update-alternatives command here.

First, generate the optional configuration options for JDK:

Update-alternatives -- install/usr/bin/jdk/root/jdk1.5.22 255

/Usr/bin/jdk is a symbolic link that points
/Etc/alternatives/jdk (given by 2nd parameters),/root/jdk1.5.22 is the actual target link, 255
Is the priority (any integer, in the automatic mode, the priority of the number is higher, is selected as the default configuration option ).

Then it is generated for JDK (if JDK is available. Skip to Section 3.3 If JDK is not used ):

Update-alternatives -- install/usr/bin/jdk/root/jdk1.6.20 0

The default jdk version is 1.5. Use update-alternatives-config jdk to switch to version 1.6.

3.3 configure JDK Environment Variables

Configure the environment variables.

Run: gedit ~ on the terminal ~ /. Bashrc

Modify the. bashrc file and add the following statement:

# Set java environment

Export JAVA_HOME =/usr/bin/jdk

Export JRE_HOME = JAVA_HOME/jre

Export CLASSPATH = $ JAVA_HOME/lib: $ JRE_HOME/lib: $ CLASSPATH

Export PATH = $ JAVA_HOME/bin: $ JRE_HOME/bin: $ PATH

It is best to set this part of code at the end of the file.

Save the file. Execute source ~ in the terminal ~ /. Bashrc

Use java-version to check whether JDK is correctly configured.

4. install other essential components

On the terminal, run the following command to install:

Apt-get install git-core gnupg flex bison
Gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
Libncurses5-dev zlib1g-dev

Because JDK has been installed separately, the sun-java5-jdk is not added to the apt-get install command line here.

5. Download the Android source code

5.1 install the repo script

First install repo. Create a new bin directory under the root directory. Run the following command on the terminal:

Cd ~

Mkdir bin

Then, add the bin PATH to the PATH:

Export PATH = $ PATH :~ /Bin

Then execute the following two lines of commands to download the repo script and modify the executable attributes:

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

Chmod a + x ~ /Bin/repo

5.2 initialize repo

First, create a directory to store the Android source code:

Mkdir mydroid

Cd mydroid

Then perform initialization with the latest list. Here we download android 2.1-r1, so added the parameter-B android-2.1_r2:

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

Your name and Email will be asked in the middle. If you want to upload code, Email must be a Google account.

After repo Initialization is successful, a message similar to the following is displayed:

Repo initialized in/root/mydroid

Finally, execute repo sync to start the synchronization code. The download speed depends on your network speed. disconnection may occur in the middle. Re-Execute repo sync to resume the download.

6. Compile the Android source code

6.1 compile and generate an image

Switch to the root directory of the android source code and execute make. It takes about three hours to compile for the first time, depending on the machine configuration. After that, the image is generated under/root/mydroid/out/target/product/generic.

6.2 compile and configure the Android SDK

After the make sdk is compiled, run the make sdk command to generate the sdk corresponding to the source code of this version.

The official Android SDK is different from the sdk compiled using make SDK when compiling the Android source code. The default image to be loaded varies with the Simulator version (one is official, one is compiled by yourself ). The following describes how to switch the SDK version freely.

First is the SDK version compiled by yourself, the actual location is/root/mydroid/out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86.

Because it is commonly used, we give it a high priority:

Update-alternatives -- install
/Usr/bin/AndroidSDK
/Root/mydroid/out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86 255

Download the official SDK in advance location is/root/android-sdk-linux_86, execute:

Update-alternatives -- install/usr/bin/AndroidSDK/root/android-sdk-linux_86 0

Then use update-alternatives -- display AndroidSDK to view the current configuration:

To switch configurations, use update-alternatives -- config AndroidSDK

Configure AndroidSDK environment variables. Run gedit ~ on the terminal ~ /. Bashrc

Add the following three lines at the end of the file:

# Set android environment

Export ANDROID_SDK_HOME =/usr/bin/AndroidSDK

Export PATH = $ ANDROID_SDK_HOME/tools: $ PATH

Save the file. Execute source ~ in the terminal ~ /. Bashrc

7. Run the compiled image in the simulator

Open the terminal and execute the android script:

Android

The following window is displayed:

Select the First Virtual Devices item on the left, and select New on the right to create an AVD.

Name: AVD Name. It can only contain letters, numbers, dots, underscores, and hyphens. The Name is "test.

Traget: Target SDK version. Select Android SDK 2.1-r1 compiled here.

SD Card: SD Card. This parameter is not set for the time being. You can set this parameter when necessary.

Skin: Skin (simulator screen resolution ).

Hardware: use the default setting.

Click Create AVD to Create an AVD. Click Start to Start the simulator. The simulator runs a self-compiled image.

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.