I recently compiled the source code of the Android operating system based on the information I saw. The result is successful, but the process is tortuous. The first thing I want to talk about is the prerequisites. This is very important, at first, I took a lot of detours because I didn't meet the prerequisites.
1, get the latest Android source code from the http://source.android.com compilation information, this is not the following compilation must be used,
However, it is indeed more accurate in all compilation materials related to the Android operating system source code.
2. Use Ubuntu Linux 12.04 lts. If you want to try it according to what I wrote, select this option, which can save your time;
3. Install related software packages
Click (here) to fold or open
- Sudo apt-Get install Git-core
- Sudo apt-Get install GnuPG
- 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 build-essential
- Sudo apt-Get install zip
- Sudo apt-Get install curl
- Sudo apt-Get install libncurses5-dev
- Sudo apt-Get install zlib1g-dev
When I wrote this article, the above installation was successful, but you will not be able to ensure it is successful, because there may be some software sources
It has changed. If this happens, you can check the latest solution on the Internet based on the keywords prompted during installation.
Is to update the software source, the following is a general method to update the software source:
[Backup Software source]
Sudo CP/etc/APT/sources. LIST/etc/APT/sources. List. Backup
(If you want to restore the original software source, run: sudo CP/etc/APT/sources. List. Backup/etc/APT/sources. List)
[Edit software source]
Sudo gedit/etc/APT/sources. List
Add and save the updated software source at the end of the file and exit.
[Update software source]
Sudo apt-Get update
4. install Java JDK
(1) If JDK and JRE have been installed in the system, uninstall them first (APT-Get remove JDK software name)
(2) Update the JDK software source
Sudo add-Apt-repository "Deb http://us.archive.ubuntu.com/ubuntu/ hard Multiverse"
Sudo apt-Get update
(3) install Java jdk6
Sudo apt-Get install sun-java6-jre sun-java6-plugin sun-java6-fonts sun-java6-jdk
(4) install Java jdk5
Sudo apt-Get install sun-java5-jdk
(5) modify the link of javadoc
Click (here) to fold or open
- CD/etc/alternatives
- Sudo RM javadoc.1.gz
- Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/man/Man1/javadoc.1.gz javadoc.1.gz
- Sudo RM javadoc
- Sudo ln-S/usr/lib/JVM/Java-1.5.0-sun/bin/javadoc
5. Set Environment Variables
Sudo gedit ~ /. Bashrc
Add at the end of the file
Click (here) to fold or open
- Java_home =/usr/lib/JVM/Java-6-sun
- Jre_home =$ {java_home}/JRE
- Export android_java_home = $ java_home
- Export classpath =. :$ {java_home}/lib: $ jre_home/lib: $ classpath
- Export java_path =$ {java_home}/bin: $ {jre_home}/bin
- Export jre_path = $ java_path
- Export java_home;
- Export jre_home;
- Export classpath;
- Home_lib = ~ /Bin/
- Export path =$ {path }:$ {java_path }:$ {jre_path }:: {home_bin };
- # Echo $ path
Run: sudo source ~ /. Bashrc
Suggestion: restart ubuntu.
6. Install the compilation tool
[Solve the problem that an android official website cannot be downloaded first]
Sudo gedit/etc/hosts
Append a sentence at the end of the file: 74.125.237.1 dl-ssl.google.com
Cd ~
Mkdir Bin
Run the following command on http://source.android.com/source/downloading.html
Curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/Repo
Chmod A + x ~ /Bin/Repo
7. Install gcc4.4
Click (here) to fold or open
- Sudo apt-Get install gcc-4.4
- Sudo apt-Get install g ++-4.4
- Sudo apt-Get install g ++-4.4-multilib
- Sudo Rm-RF/usr/bin/GCC/usr/bin/g ++
- Sudo ln-S/usr/bin/gcc-4.4/usr/bin/GCC
- Sudo ln-S/usr/bin/g ++-4.4/usr/bin/g ++
8. Install Python
Sudo apt-Get install Python
9. Download the android source code
Click (here) to fold or open
- Mkdir ~ /Work/android-cts-2.2_r8
- Cd ~ /Work/android-cts-2.2_r8
- Repo init-u https://android.googlesource.com/platform/manifest-B android-cts-2.2_r8
- Repo sync
This is a long process and it is best to do it during a vacation. ,
10. Comment out information about Java version Verification in the source code.
Cd ~ /Work/android-cts-2.2_r8
Gedit./build/CORE/Main. mk
Click (here) to fold or open
- # Check for the correct version of Java
- # Java_version: = $ (shell Java-Version 2> & 1 | head-N 1 | grep '["] 1 \. 5 [\." $]')
- # Ifeq ($ (Strip $ (java_version )),)
- # $ (Info ************************************ ************************)
- # $ (Info you are attempting to build with the incorrect version)
- # $ (Info of Java .)
- # $ (Info $ (Space ))
- # $ (Info your version is: $ (shell Java-Version 2> & 1 | head-N 1 ).)
- # $ (Info the correct version is: 1.5 .)
- # $ (Info $ (Space ))
- # $ (Info please follow the machine setup instructions)
- # $ (Info $ (Space) http://source.android.com/download)
- # $ (Info ************************************ ************************)
- # $ (Error stop)
- # Endif
- # Check for the correct version of javac
- # Javac_version: = $ (shell javac-Version 2> & 1 | head-N 1 | grep '["] 1 \. 5 [\." $]')
- # Ifeq ($ (Strip $ (javac_version )),)
- # $ (Info ************************************ ************************)
- # $ (Info you are attempting to build with the incorrect version)
- # $ (Info of javac .)
- # $ (Info $ (Space ))
- # $ (Info your version is: $ (shell javac-Version 2> & 1 | head-N 1 ).)
- # $ (Info the correct version is: 1.5 .)
- # $ (Info $ (Space ))
- # $ (Info please follow the machine setup instructions)
- # $ (Info $ (Space) http://source.android.com/download)
- # $ (Info ************************************ ************************)
- # $ (Error stop)
- # Endif
11. Last preparation before Compilation
Click (here) to fold or open
- Cd ~ /Work/android-cts-2.2_r8
- Source./build/envsetup. Sh
- Lunch full-Eng
12. Compile source code
After a long preparation, we can finally compile it.
Click (here) to fold or open
- Cd ~ /Work/android-cts-2.2_r8
- Make
This is also a long process. Please wait patiently during the holidays.
13. Run the compilation command to view the result.
If the above sudo gedit/etc/profile
If the compilation is successful, we can use the virtual machine to check the results.
(1) download the SDK to the android official website, http://developer.android.com/sdk/index.html
(2) decompress the downloaded SDK to the main folder and change it to Android-SDK-Linux.
(3) sudo gedit/etc/profile
Set
Export Path = "$ path :~ /Android-SDK-Linux/tools"
Last file written
(4) sudo gedit ~ /. Profile
Set
Click (here) to fold or open
- Export Path = "$ path: $ home/work/android-cts-2.2_r8/out/host/linux-x86/bin"
- Android _ product_out = $ home/work/android-cts-2.2_r8/out/target/product/generic
- Export android_product_out
The end of the written file.
(5) use the android command to open the android SDK Manager interface and download the SDK platform for installing android2.2.
(6) Finally, you can check the results.
Click (here) to fold or open
- Cd ~ /Work/android-cts-2.2_r8/out/target/product/generic
- Emulator-image system. IMG-data userdata. IMG-ramdisk. img