This section focuses on downloading and compiling the Android source code and the Linux kernel source code, and how to build both of these development environments.
I. Download, compile and test Android source code
(1) Configure Android source code download environment
1. Create a directory to hold the download script file (repo) (you can put the script file in any directory, use ~/bin here)
#mkdir ~/bin
#PATH =~/bin: $PATH
2. Download the repo script file (for downloading Android source code)
#curl Https://dl-ssl.google.com/dl/googlesourse/git-repo/repo > ~/bin/repo
#chmod a+x ~/bin/repo
3. Create a directory to hold the Android source code (can be placed in other directories)
#mkdir Android_source
#cd Android_source
4. Initialization
#repo Init-u Http://android.googlesource.com/platform/manifest
5. Start downloading Android source code
#repo sync is going to be a long wait.
Android Source code directory structure parsing
(2) Download part of Android source code
There are 2 ways to do this:
Method 1: Use the Repo Sync command (you still need to initialize with Repo init before performing the Repo Sync command)
Method 2: Use the git clone command to download the specified project source code
(3) Compiling Android source code
1. Initializing the compilation environment
#source build/envsetup.sh or. build/envsetup.sh
envsetup.sh script file is mainly used to initialize some compiling commands, such as mm, MMM and so on. where mm, MMM is two very important commands, they can compile the Android source code specified in the project.
2. Select the target and set the compilation target using the lunch command
#lunch Full-eng
3. Compiling Android Source code
#make-j4 (If you do not add-jn command-line arguments to a multicore pc, the make command will only compile with one CPU core)
Two. Download and compile the Linux kernel source code
(1) Download the Linux kernel source code. Execute the following command to download the latest Linux kernel source code:
#git Clone Http://android.googlesource.com/kernel/common.git
After the download is complete, there will be a common directory in the current directory, enter the directory, and execute the following command to see which remote Repository is currently available.
#git branch-a
We can export the latest Linux kernel from the repository based on the repository situation, such as: #git checkout-b android-3.0 remotes/origin/android-3.0
(2) Install the Android kernel's compilation environment
(3) Configuring and compiling the Linux kernel (assuming that the Linux kernel source code directory is/root/linux_kernel)
1. Compile the Linux kernel using the following command:
#export Path=/root/compliers/arm-none-linux-gnueabi/bin: $PATH
#cd ~/linux _kernel
#make clean, which clears most files generated by compilation (. O,. Ko, and so on), but retains the configuration file.
#make
2. Generally the newly downloaded Linux source code root directory does not have a. config file. However, this file determines what functions and modules are generated by the Linux kernel that is compiled. Therefore, the first time you get the Linux kernel, you should first configure the Linux kernel.
#make Menuconfig, configure the Linux kernel in an interface-style menu
Go to the submenu of the "General Setup" menu item. Select the "cross-compiler tool prefix" menu item, press ENTER, ask for the cross compiler prefix, enter arm-none-linux-gnueabi-, exit Save settings.
After all the settings have been completed, execute the make command to compile the Linux kernel.
Once the Linux kernel is successfully compiled, a zimage file is generated in the <linux kernel source root directory >/arch/arm/boot directory, which is the Linux kernel binary version.
Three. Use the following command to test the Linux kernel in the Android emulator (requires the use of a zimage file compiled by goldfish)
#emulator-AVD Myavd-kernel/root/kernel/goldfish/arch/arm/boot/zimage
Where Myavd is an AVD name.
Learn how to download and compile your source code