4.1 Download compile and test source code
Android source code consists of a lot of things, one is Android system application code, Android SDK with various tools, Android NDK source code, HAL source code.
1. Configure the Android source code download environment
Before downloading the Android source code, you must perform a series of commands on the Linux terminal to configure the download environment.
First step: Create a directory to hold the download script file (repo)
# mkdir ~/bin
# Path=~/bin: $PATH
Step two: Download the repo script file
# Curl Https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
# chmod a+x ~/bin/repo (Repo is a python-to-git package that simplifies the operation of downloading Android source code)
Step three: Create a directory to hold the Android source code
# mkdir Android_source
# CD Android_source
Fourth Step: Initialize
# Repo Init-u https://android.googlesource.com/platform/manifest-b ANDROID-4.0.1_RL
Fifth step: Start downloading the android source download process the network can hardly do other things code
# Repo Sync
After executing the above command, will be realistic some information and then began to download the Android source code, followed by a long wait, according to the majority of the country can reach the speed, at least 4 hours to finish.
Download part of Android source code
Method 1 using the Repo Sync command
# Repo Sync platform/bootable/recovery
Method 2 using the git clone command
# git clone http://android.googlesourse.com/<project name>
2 compiling Android source code
First step: Initializing the compilation environment
# source Build/envsetup.sh
Or
# . build/envsetup.sh
Step Two: Select the target
# Lunch Full-eng
Step three: compiling Android source code
# MAKE–J4
Not only does it take a long time to download the Android source code, it also takes a long time to fully compile the Android source code. When the compilation is complete, an out directory is generated in the root directory of the Android source code.
The Out directory is the default directory that holds the target files generated by the compiled Android source code.
-Target (indicates the target machine, if compile time defines Target_strip_module=false, this directory is Debug/target) The main two directories are host and Target, the former represents the tool generated in the host (x86), The latter represents the content that the target machine (default is ARMV5) runs.
4.2 Download and compile the Linux kernel source code
Download the latest version of the kernel source code
# git clone https://android.googlesourse.com/kernel/common.git
See which remote repositories are available
# git Branch-a
Exporting the Linux3.0 kernel
# git check out-b android-3.0 remotes/origin/android-3.0
Download the kernel
# git clone http://android,googlesourse.com/kernel/goldfish.git
Export Goldfish
# git checkout-b android-goldfish-2.6.29 remotes/origin/android-goldfish-2.6.29
Linux Kernel source Directory
Arch: Contains code related to hardware architecture, each of which occupies a corresponding directory.
Block: Partial block device Drive
Crypto: Commonly used encryption and hashing algorithms (such as AES, SHA, etc.), as well as some compression and CRC check algorithms.
Documentation
Drivers: Device drivers, each of which consumes a subdirectory, such as char, block, net, MTD, I²c, and so on.
FS: Supports various file systems, such as ext, FAT, NTFS, JFFS2, etc.
Include: header files, System-related header files are placed under the Include/linux subdirectory.
INIT: Kernel initialization code.
IPC: Code for interprocess communication
Kernel: The core of the kernel, including the scheduling of the process, timers, and so on, and some of the peace platform related to the code in the Arch/*/kernel directory.
LIB: library file code.
MM: Memory management code, and part of the platform-related code is placed in the ARCH/*/MM directory.
NET: Network-related code, the realization of a variety of common network protocols.
Install the Android kernel's build environment
1. Copy the arm-linux-gcc-4.3.2.tgz file and the arm-none-linux-gnueabi-arm-2008q3-72-for-linux.tar,bz2 file to the working directory
2. Unzip the two files above
3. Verify that the cross compiler is successfully installed
# ls/user/local/arm-1
4. Installing LIBNCURSES5
# Apt-get Install Libncurses5-dev
Configuring and compiling the Linux kernel
# Export Path=/root/compilers/arm-none-linux-gnueabi/bin: $PATH
#cd ~/linux_kernel
#make Clean
#make
Execute the following four configuration commands in the Linux source code directory
Make Config
Make Manuconfig
Make Oldconfig
Make Xconfig
After successfully compiling the Linux kernel, a zlmage file is generated in the <linux kernel source directory >/arch/arm/boot directory, which is a binary version of the Linux kernel and can be installed directly on the development version using Zlmage. You can also test in the Android emulator with commands.
# EMULATOR-AVD Myavd-kernel/root/kernel/goldfish/arch/arm/boot/zlmage
Download and compile the source code