Download and compile the Android platform source code in Ubuntu

Source: Internet
Author: User
Document directory
  • 1. Install JDK
  • 2. Install the compilation tool
  • 3. Create a working directory
  • 4. Install the repo version management tool (based on Git-based development to facilitate git Resource Management)
  • 5. Prepare to download the android source code.
  • 6. configure a repo account
  • 7. Download the source code of Android platform.
  • 8. Add a Public Key
  • 9. Select a version
  • 10. Update environment variables (select the compilation target)
  • 11. Select the compilation target object
  • 12. Compile the android source code
  • 13. Set environment variables first
  • 14. Run the compilation result

This article describes how to download and compile the android source code in Ubuntu. What is the android source code? Android Source Code refers to the Android platform and software source code, not just the Linux kernel. We often say that Linux kernel is only an integral part of this open source project. So when do we need the andriod source code? To add and modify the driver, solidify the APK application, and customize the OS, permissions, and service modification or solidification, most of them need to be modified to the android source code. Of course, you can also use the pure upper-layer APK development, the android source code is relatively large, and there are about 3G + (excluding the Linux kernel). Therefore, you have configured the disk space before downloading it to avoid wasting one night's time.

The following are the self-testing environments:

  • Ubuntu
    10.10x86
  • For Android 2.3

References:

Android source code Website: http://source.android.com

Compile reference 1: http://source.android.com/source/initializing.html

Compile Reference 2: http://source.android.com/source/downloading.html

Compile Reference 3: http://source.android.com/source/building.html

Compile reference 4: http://source.android.com/source/building-devices.html

Next we will summarize the download and compilation process of the android source code on Ubuntu 10.10. The official documents are detailed. This article focuses on summary and supplement. If you still have any questions, please refer to the official webpage or leave a message.

I. Initial environment Setup 1. Install JDK

The command format for installing Java 6 is as follows:

Java 6 (for Android 2.1 + ):

$ Sudo add-Apt-repository "Deb http://archive.canonical.com/lucid partner"

$ Sudo add-Apt-repository "Deb-Src http://archive.canonical.com/ubuntu lucid partner"

$ Sudo apt-Get update

$ Sudo apt-Get install sun-java6-jdk

If you want to switch to the Java version (when multiple Java versions are installed), enter the following command:

Sudo Update-alternatives -- config Java

Sudo Update-alternatives -- config javac

Run the following command to view the current Java version:

Java-version

Supplement: how to switch between two versions of Java JDK

Due to development needs, I have to install Java 5 and Java 6 on Ubuntu. How can I switch from one version of Java to another? Update-Java-alternatives can help you implement this function.

You can use Update-Java-alternatives-L to view the installed JDK version.

 
 
  1. dallas@dallas-desktop:~/work$ update-java-alternatives -l 
  2. java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun 
  3. java-6-sun 63 /usr/lib/jvm/java-6-sun 

Then you can use Update-Java-alternatives-s XXX to select the JDK version you want to use.

 
 
  1. update-java-alternatives -s java-6-sun

2. Install the compilation tool

Run the following command to install all required compilation tools at a time:

$ 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 libz-dev libreadline5-dev

Tian Yuan in the test using the above configuration, it seems that nothing is missing, if a software package is missing, you can use the command and then separately supplement the installation, such as installing the libc6-dev-i386, the command is as follows:

Sudo apt-Get install libc6-dev-i386

Ii. Download Android source code 3. Create a working directory

Go to the working directory (such as works) and create the bin directory:

Mkdir ~ /Works

Mkdir ~ /Works/android_dev

Cd ~ /Works/android_dev

Mkdir Bin

4. Install the repo version management tool (based on Git-based development to facilitate git Resource Management)

Curl http://android.git.kernel.org/repo> ~ /Works/android_dev/bin/Repo

CD Bin

Chmod A + x Repo

More references for repo: http://source.android.com/source/version-control.html

5. Prepare to download the android source code.

Cd ~ /Works/android_dev

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

The latest version (2.3) is downloaded by default. To download other versions, use a command similar to the following command (hereinafter referred to as "version ):

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

6. configure a repo account

Git config -- global user. Email "[email = abc@gmail.com] abc@gmail.com [/Email]"

Git config -- global user. Name "ABC"

7. Download the source code of Android platform.

./Bin/repo sync

Due to the large source code of Android, the complete source code of the new version is now more than 3 GB, Which is downloaded from the GG official website at a very slow speed (about one night ), you can go home and go to bed or go out all night after execution. Make sure that you have sufficient disk space before downloading.

To download the kernel (that is, the Linux kernel source code ):

$ Repo sync Kernel

8. Add a Public Key

$ GPG -- Import

This command is the public key for interactive import. Refer to the official instructions on Google. This public key is used to sign tags to indicate that this version is the release version (translation seems a bit problematic here, the original statement is that the key is used to sign annotated tags that represent releases) This step can be compiled normally even if it is not executed. However, we recommend that you add it when compiling the release version, GPG (GNU Privacy guard.pdf is an open-source encryption software. For more information, see the official website downloading.html.

9. Select a version

$ Git tag-V tagname

You only need to select the version. It can be an ordinary version, a lite version, or other version. Simply press the number and press Enter.

3. Compile Android source code 10. Update environment variables (select the compilation target)

Source build/envsetup. Sh

11. Select the compilation target object

Command Format: BUILD-BUILDTYPE, where build and buildtype can refer to the official web page [compilation Reference 3 and compilation reference 4 ]. If the command is not supported or an error occurs, a message is displayed. For example:

Lunch full-Eng

Other commands such,

Lunch full_crespo-userdebug

The summary format is as follows:

Lunch (generic, full, full_crespo, crespo4g, passion)-(user, userdebug, Eng)

The above is the default setting. If you need to use the source build/envsetup. Sh command to view the settings, Android 2.3 Code supports three target models, including HTC and sumpers. For more information, see the official website mentioned above. The Nexus S and Nexus S 4G are recommended for Android open-source projects, while Nexus One is only a test machine and is not supported (why? Native Code cannot be burned to Nexus One ???) after compilation ??).

12. Compile the android source code

Make-J4

Note: This command is an JN with a horizontal bar (at first, tianyuan was always unable to run, and it was directly used to make the command. It was only three days after it was found that a lever was lost * _ *). According to the official introduction, later-JN is the number of sub-CPUs of your machine * Number of cores * Number of Single-CPU threads * (1 or 2). The compilation time is about 40 minutes-2 hours, depending on the sub-performance, the final compilation result is as follows:

~ /Works/android_dev/out

In addition, we recommend that you back up the entire directory of/Works/android_dev before compilation. If you reinstall the system next time, you can directly copy it for use, during compilation, you may need to set the permission (chmod-r 777 android_dev). Otherwise, there may be many errors.

Iv. run Android Virtual Machine 13. Set environment variables first

The command is as follows:

Export android_product_out =/Works/android_dev/out/target/product/generic

After the configuration is complete, log out first, and then log in to login to update the environment variable.

Note that the environment variable settings here can also be put in the system configuration file at first ,. bashrc, The tianyuan test seems to be so OK. The following items should be set on the Internet (if there is a problem with running, you can try to use it, some paths in the command may need to be replaced with your own settings ):

Export android_dir = ~ /Works/android_dev

Export android_product_out =$ {android_dir}/out/target/product/generic

Export android_product_out_bin =$ {android_dir}/out/host/linux-x86/bin

Export path =$ {path }:$ {android_product_out_bin }:: {android_product_out };

14. Run the compilation result

Go to the android_dev/out/host/bin/directory and run:

Emulator -- debug-init-skin QVGA-L

Or:

./Emulator

The robot interface is displayed.

Supplement:

After the image is compiled successfully, it will be in the directory ~ Some image files ramdisk. IMG system. IMG userdata. IMG android-info.txt are generated under/Works/Android/out/target/product/generic, which will be described later.

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.