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


 

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.3 apt-Get install gcc-4.3 G +-4.3 and then enter/usr/bin CD/usr/bin to create a soft connection ln-s gcc-4.3 GCC ln-S g ++-4.3g ++

Note: QQ technology exchange group: add one if you are interested in 108614806.

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.