1. Obtain the android source code
Git is an open source distributed version control software developed by Linux Torvalds (father of Linux) to help manage Linux kernel development. It is different from the centralized version control system like Subversion and CVS. In a centralized version control system, there is only one warehouse (repository) and many working directories (working copy ), in distributed version control systems such as git (other major distributed version control systems include bitkeeper, mercurial, GNU arch, bazaar, darcs, SVK, and monotone ), each working directory contains a complete repository that supports offline work. Local submission can be submitted to the server later.
Because Android is composed of multiple projects, such as kernel, Dalvik, bionic, prebuilt, and build, It is very troublesome to use git to obtain them one by one, therefore, the android project has compiled a Python script named repo to manage the repositories of these projects in a unified manner, making the project acquisition easier.
To install git on Ubuntu 8.04, you only need to set the correct update source and use apt-Get. APT-get is a Linux Command, it is mainly used to search, install, upgrade, and uninstall software or operating systems from software warehouses on the Internet.
The apt-GET command generally requires the root permission for execution, so it is generally followed by The sudo command.
Sudo apt-Get install Git-core curl
This command installs Git-core and curl from the software repository on the Internet.
Curl is a File Transfer tool that uses the URL syntax to work in the command line mode. It supports many protocols, including FTP, ftps, HTTP, https, and Telent, we need to install it to obtain the repo script file from the network.
Curl http://android.git.kernel.org/repo> ~ /Bin/Repo
This command downloads the repo script file to the/bin directory of the current home directory and saves it in the file repo.
Finally, we need to grant the repo file executable permission.
Chmod A + x ~ /Bin/Repo
Next, we can use the repo script, git, and curl software to obtain the android source code :)
First, create a directory, such ~ /Android.
Run the following command to obtain the source code:
Repo init-u git: // android.git.kernel.org/platform/manifest.git
This process will take a long time (I downloaded it for one day). After the download is complete, I will see a prompt such as repo initialized in/Android, indicating that the local version library has been initialized, and contains the latest sourcecode.
If we want to use the code of a branch version instead of the main line code, we need to use the-B parameter to specify the branch name, for example:
Repo init-u git: // android.git.kernel.org/platform/manifest.git-B cupcake
If we only want to get the code of a project, such as kernel/common, we do not need a repo script. We can directly use the GIT tool. If we carefully study the repo script, we will find that, the repo script actually organizes git tools to get various projects and organize them into the same project android.
Git clone git: // android.git.kernel.org/kernel/common.git
We obtained various projects using the repo script above, and then we need to synchronize the entire android code tree to the local, as shown below:
Repo sync project1 project2...
I use the repo sync command to directly synchronize all projects to the local device.
Ii. source code compilation
After the synchronization is complete, go to the android directory and use the make command to compile the SDK. the following error message is displayed:
Host C: libneo_cgi <= external/clearsilver/cgi. c
External/clearsilver/cgi. C: 22: 18: Error: zlib. h: no such file or directory
This error is because we lack the zlib1g-dev and need to install it from the software repository using the apt-GET command, as shown below:
Sudo apt-Get install zlib1g-dev
Similarly, we also need to install the following software in sequence.
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.
At this time, you will find many errors that cannot be compiled by Java files, open the android source code. We can see that there are many Java source files in Android/Dalvik/libcore/DOM/src/test/Java/org/W3C/domts, this means that JDK must be installed before compiling android.
First download the jdk-6u16-linux-i586.bin file from the sun official website and install it.
In ubuntu 8.04, the/etc/profile file is a global environment variable configuration file, which applies to all shells. When we log on to the Linux system, first start the/etc/profile file, and then start ~ /. Bash_profile ,~ /. Bash_login or ~ /. One of the profile files has the same order of running as the preceding sorting. If ~ /. If the bash_profile file exists, it is generally executed ~ /. Bashrc file.
So we only need to put the JDK directory in/etc/profile, as shown below:
Java_home =/usr/local/src/jdk1.6.0 _ 16
Path = $ path: $ java_home/bin:/usr/local/src/android-sdk-linux_x86-1.1_r1/tools :~ /Bin
Restart the machine and enter the Java-version command. The following message indicates that the configuration is successful:
Java version "1.6.0 _ 16"
Java (TM) se Runtime Environment (build 1.6.0 _ 16-b01)
Java hotspot (TM) Client VM (build 14.2-b01, mixed mode, sharing)
After the entire project is compiled, the following prompt appears:
Target System FS image: Out/target/product/generic/obj/packaging/systemimage_unopt_intermediates/system. img
Install system FS image: Out/target/product/generic/system. img
Target RAM disk: Out/target/product/generic/ramdisk. img
Target userdata FS image: Out/target/product/generic/userdata. img
Installed file list: Out/target/product/generic/installed-files.txt
Root @ dfsun2009-desktop:/bin/Android #
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-1.1_r1 in the system, This SDK is:
Http://dl.google.com/android/android-sdk-linux_x86-1.1_r1.zip: Linux
MacOS: http://dl.google.com/android/android-sdk-mac_x86-1.1_r1.zip
Windows: http://dl.google.com/android/android-sdk-windows-1.1_r1.zip
After decompression, add the/usr/local/src/android-sdk-linux_x86-1.1_r1/tools directory to the system environment variable/etc/profile.
Then find the compiled Android directory file out, we found that many applications in Android/out/host/linux-x86/bin, these applications are the basis for Android to run, therefore, we need to add this directory to the system path at $ home /. add the following content to the profile file:
Path = "$ path: $ home/Android/out/host/linux-x86/bin"
Next, we need to load the android image file to emulator so that emulator can see the actual running effect of Android. Add the following content to the $ home/. profile file:
Android_product_out = $ home/Android/out/target/product/generic
Export android_product_out
Then restart the machine.
Enter the simulator directory and start the simulator.
CD $ home/Android/out/target/product/generic
Emulator-image system. IMG-data userdata. IMG-ramdisk. img
Summarize the key points in the installation process:
1: JDK version is required
2: Use the following command to ensure that all required software is correctly installed.
Sudo apt-Get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential Python valgrind curl git
3: the memory and virtual memory are above 2 GB. You can use the command line free-m to check whether the memory is sufficient. If the memory is not enough, the terminal stops.