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 Construction
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.
Dallas @ dallas-desktop :~ /Work $ update-java-alternatives-l
Java-1.5.0-sun 53/usr/lib/jvm/java-1.5.0-sun
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.
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 the 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 the 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.
4. Run the 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.