Obtain and compile the source code for Android Development

Source: Internet
Author: User

1. Obtain the android source code

Google uses the version control tool git to manage the android source code. To obtain the android source code of various versions, it must be obtained online from the Google repository. Google also developed a repo tool for this purpose, it is a script written in Python. The main function is to download the android source code from the Google repository.

The specific acquisition process is: ubuntu10.4:

  1. Install the GIT Tool

Google uses the distributed version control system git to manage the android source code. For details, refer to the following command to install the tool.

Sudo apt-Get install Git-core GnuPG

  1. Install JDK

The upper-layer apps of the Android system are developed using Java, so that the Java
SDK, General Ubuntu systems do not have built-in JDK, so we need to manually install JDK, android2.3 requires JDK 6, and Android of earlier versions may need JDK 5. The command for obtaining and installing the SDK is as follows:

Sudo apt-Get install sun-java6-jre sun-java6-plugin

Sudo apt-Get install sun-java6-jdk

  1. To install other android packages, run the following command:

Sudo apt-Get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl valgrind

  1. Install the repo script command tool to obtain the source code. Because it is only a script file, you only need to obtain it and do not need to install it. The command is:

Curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/Repo

Chmod A + x ~ /Bin/Repo

  1. Obtain the android source code with the following command:

Repo init-u https://android.googlesource.com/platform/manifest

The above method obtains the latest Android Source Code. For example, when I write this article, I obtain the source code of android4 and the source code of the specified version. The command is:

Repo init-u https://android.googlesource.com/platform/manifest
-B android-2.3.3_r1

Both of the above methods only establish a connection with the android source code provided by Google and have not been downloaded. To download the desired code, run the following command:

Repo sync

Download takes a long time, depending on network conditions and computer configurations, But it supports resumable data transfer.

2. Compile the android source code

Before compiling the android source code, you need to modify several files.

1. Because the android source code is compiled on a 64-bit PC by default, You need to modify the following files:

/External/clearsilver/cgi/Android. mk

/External/clearsilver/CS/Android. mk

/External/clearsilver/Java-JNI/Android. mk

/External/clearsilver/util/Android. mk

Find the local_cflags and local_ldflags variables and modify them:

# Local_cflags + =-M64

# Local_ldflags + =-M64

Local_cflags + =-M32

Local_ldflags + =-M32

2. Modify the main. mk file in the build/Core directory.

# Ifneq (64, $ (findstring 64, $ (build_arch )))

Ifneq (i686, $ (findstring i686, $ (build_arch )))

3. Execute the make command in the root directory of the android source code directory. If there are no errors, four files will be generated:

Out/target/product/generic/obj/packaging/systemimage_intermediates/system. img

Out/target/product/generic/system. img

Out/target/product/generic/ramdisk. img

Out/target/product/generic/userdata. img

3. Install the compiled image on the simulator.

1. Modify the environment variables, add the emulator command to the environment variables, or directly go to the command folder out/host/linux-x86/bin to directly execute the command.

2. Run the simulator command:

Emulator./out/target/product/generic-system. IMG-data userdata. IMG-ramdisk. img

Because the android Source Code does not contain the Linux kernel, the simulator uses the kernel-qemu, which is located:
Prebuilt/Android-arm/kernel-qemu

Final startup Effect

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.