Download and compile the android source code in Ubuntu 10.04

Source: Internet
Author: User
Tags gnupg

I. Prepare the PC work environment

First install some required Toolkit: (configure the following environment based on the installed ubuntu 64-bit and 32-bit systems)

 

Ubuntu Linux (32-bit x86 ):
Sudo apt-get install git-core gnupg
Sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev
Build-essential zip curl libncurses5-dev zlib1g-dev

Ubuntu Linux (64-bit x86 ):
Sudo
Apt-get install git-core gnupg flex bison gperf build-essential zip
Curl sun-java5-jdk zlib1g-dev gcc-multilib g ++-multilib libc6-dev-i386
Lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev
Lib32readline5-dev lib32z-dev


 

Download jdk 1.5:

Apt-get install sun-java5-jdk

Set environment variables.
Based on your own java installation, you can add the following two lines to the. bashrc file:

Gedit ~ /. Bashrc (Open bashrc)

Export JAVAHOME =/usr/lib/jvm/java-1.5.0-sun (find the java and javac Paths Based on the jdk installation path of your own machine)
Export PATH = $ PATH: $ JAVAHOME/bin: $ JAVAHOME/jre/bin: $ JAVAHOME/bin/lib
Export CLASSPATH =.: $ JAVAHOME/jre/bin: $ JAVA_HOME/lib

 

Ii. Code download

In the user directory, create a directory for storing Andorid and a bin directory.
1. Install Git and Repo tools for version management and Code Synchronization
Sudo apt-get install git-core curl
Mkdir sourcecode

Cd sourcecode
Mkdir bin
Cd bin
Curl
Http://android.git.kernel.org/repo

> Repo
Sudo chmod a + x repo (get repo permission)

You can modify the environment variables for the repo command and add the following to the. bashrc file:
Export Path = $ Ptah :~ /Bin/(never miss "~", Overwrite the path. Some commands will be lost. Optional)

2. Download source of Android;
Create a directory for saving the source code in the android directory, androidsrc.

Mkdir androidsrc

CD fandroidsrc

../Bin/repo init-u git: // android.git.kernel.org/platform/manifest.git (default master version, which is used for development and testing and is unstable)

Or obtain the cupcake branch.

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

(If the PATH environment variable is set above, use repo init-u git: // android.git.kernel.org/platform/manifest.git)
After the settings are complete, start to synchronize the code (depending on the network needs several hours or days );

../Bin/repo sync
(If the environment variable of PATH is set above, use repo sync directly)

Iii. Compilation of systems and development tools

The Android file system has built-in optimized cross-compilation tools and provides verified makefiles for all source code. Therefore, the overall compilation of the system is relatively simple, the basic functions of the official version have been included in makefile. If you want to add some functions, you can go to build/target/product/to modify the corresponding. mk file. For example

To add a Chinese Input Method, follow these steps:

# Cd/home/myandroid/androidsrc/build/target/product/
# Gedit generic. mk
Open this file, add PinyinIME to PRODUCT_PACKAGES, save and exit. In this way, the Chinese input method will also be compiled into the system during the overall compilation.

Start System Compilation:

# Cd/home/myandroid/androidsrc/

# Make
During the first overall compilation, the process lasted for about 2 to 3 hours. By default, an out folder is generated in the/home/myandroid/androidsrc directory, all the compilation items are in this directory. If you want to change the directory of the generated file, please refer to the instructions and options in the./build/buildspec. mk. default file. It is very easy to understand. The compilation mainly generates some objects under out/target/product/generic/, such as system. img.

2. Compilation of development tools
Android provides complete development tools and cross-compilation tools, all of which are included in the source code. Therefore, you can obtain a variety of development tools as long as the source code is correctly compiled, in addition, Android porting also requires the support of these tools.
The steps for compiling Android development tools are as follows:
# Cd/home/myandroid/androidsrc/
# Make SDK

This compilation mainly generates objects in the out/host/directory.

# CdS/out/host/linux-x86/SDK/
We can see that there is a folder named android-sdk_eng.root_linux-x86, which basically contains the android simulator and all the development debugging tools. Open this folder and you can see that it consists of the following parts:
-Add-ones-New Tool Path to be added
-Docs-descriptions of simulators and various development tools
-Platform-files required by simulators and development tools
-Tools-simulator and development tool applications

Iv. simulator usage

Go ~ Under the/android-sdk_eng.root_linux-x86/tools directory, there are a lot of Android tools, where the simulator corresponds to the application is emulator. The following describes how to use the simulator correctly:
#./Android create avd-n NO1-t 1
This command will go into the process of creating avd. After you make some choices as needed, the avd named NO1 will be created successfully. In the future, you can use the created avd to use the simulator. Versions earlier than 1.4 do not need to be created in this way. Versions later than 1.5 cannot be created correctly. Avd is short for android virtual machine.

#./Android list avd
Enter the command to check whether the creation is successful. If the creation is successful, it is listed.
#./Emulator-avd NO1
Start the simulator named NO1 that you just created, and use the default kernel and file system, that is ~ /Android-sdk_eng.root_linux-x86/platform/path for the kernel and file system. If there is no problem, we can see the Virtual Interface of the Android operating system.

V. File System Extraction

The extraction of file systems that Android can run on the Development Board depends on the simulator. The specific operation steps are as follows:

1. Run the simulator on a virtual device with SDcard
# Cd/home/myandroid/androidsrc/out/android-sdk_eng.root_linux-x86/tools/
#./Mksdcard-l 200 M/home/sdcard. img
The mksdcard open tool is used to create a m sdcard under the/home directory. img is used for the interaction between data in the simulator and external data. The size of the virtual SD card should not be less than 100 MB; otherwise, during the subsequent file system packaging process, there may be insufficient storage space for SD cards.

#./Android create avd-n cupcake-t-c/home/sdcard. img 1
Create a virtual device named cupcake with sdcard.

#. /Emulator-avd cupcake-sysdir/home/myandroid/androidsrc/out/target/product/generic-data/home/myandroid/androidsrc/out/target/product/generic/userdata. img-ramdisk/home/myandroid/androidsrc/out/target/product/generic/ramdisk. img-kernel/home/myandroid/androidsrc/prebuild/android-arm/kernel-qemu
Use a virtual device named cupcake to start the simulator and specify the image file paths of the system and data. The simulator kernel uses prebuild/android-arm/kernel-qemu. Of course, you can also use a self-compiled kernel image.

2. Use tools to get the file system from the running simulator and put it in sdcard

Open a new terminal and perform the following operations:
# Cd/home/myandroid/androidsrc/out/android-sdk_eng.root_linux-x86/tools/
#./Adb remount
Here, the remount option of the adb tool is used to change the system directory permission in the simulator to readable and writable.
#./Adb push tar/system/bin
Here, the push command of the adb tool is used to add the tar application prepared using busybox to the/system/bin directory of the simulator. We will not introduce the use of busybox here. You can read the articles on the Internet by yourself.

#./Adb shell
Use the adb tool to enter the shell of the simulator.

Go to the shell of the Android simulator and perform the following operations:
# Tar cvf/sdcard/system.tar/system
# Tar cvf/sdcard/userdata.tar/data

Here, we use the tar application added to the simulator to package all the content in the system and data directories and store it in sdcard. After the operation is completed, the system.tarand userdata.tar files are saved in the sdcarddirectory. If yes, the package is successful.
# Exit
Exit shell and disable the simulator.

# Mount-o loop sdcard. img/mnt
# Cd/mnt

Mount the virtual SD card to the/mnt directory. after entering the/mntdirectory, copy system.tarand userdata.tar. The file system is extracted.

After testing, we found that the mkyaffsimage provided by Android is used to directly package the/out/target/product/generic/system directory and create a system. IMG can also be used completely, but I do not know userdata. how to Create IMG? I hope someone can give me some advice. When using mkyaffs2image to create a file system image, pay attention to some configuration file permissions. For example, the file permissions under/system/usr/keylayout are problematic and need to be modified, otherwise, the generated image cannot be normally used, such as the keyboard, after being loaded in the simulator.

 

Compilation error:

Frameworks/base/tools/aidl/ast. cpp: 10: Error: 'fprintf' was not declared in this scope Error

Solution: download gcc-4.3 and g ++-4.3apt-get install gcc-4.3 g ++-4.3 and then enter/usr/bincd/usr/bin to create a soft connection ln-s gcc-4.3 gccln-s g ++ -4.3g ++

 

 

Related Article

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.