Http://www.cnblogs.com/jacktong/archive/2010/08/24/1807548.html
This article mainly refer to the official documentation (http://source.android.com/download) and online related information (http://blog.csdn.net/HKjinzhao/archive/2009/03/18/4002326.aspx,http://www.williamhua.com/2009/04/30/how-to-build-android-15-kernel-image ). The documents on the Internet are outdated or incorrect for some of the latest andorid code. This document is self-tested to ensure it is feasible. I am not familiar with using eclipse, so I have not configured eclipse.
Compilation environment: ubuntu9.10, which is not supported by the Widnows platform currently.
1) install necessary software environments
$ 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
This is officially recommended. If some commands cannot be found during compilation, Apt-Get it. Possible packages are:
$ Sudo apt-Get install make
$ Sudo apt-Get install gcc
$ Sudo apt-Get install g ++
$ Sudo apt-Get install libc6-dev
$ Sudo apt-Get Install patch
$ Sudo apt-Get install texinfo
$ Sudo apt-Get install zlib1g-dev
$ Sudo apt-Get install valgrind
$ Sudo apt-Get install python2.5 (or later)
It should be noted that the official documentation said that if you can use sun-java6-jdk problems, you have to use sun-java5-JDK. Tests showed that if only make (make does not include make SDK), it is no problem to use sun-java6-jdk. The Make SDK has a problem. Strictly speaking, there is a problem with make doc. It requires the javadoc version 1.5.
Therefore, we 'd better install the sun-java6-jdk after installing the sun-java5-jdk, or just install the sun-java5-jdk. Here, both sun-java6-jdkand sun-java5-jdkare installed, and only javadoc.1.gz and javadoc are modified. Because only these two are used by the make SDK. In this case, except that the javadoc tool uses version 1.5, all other tools use version 1.6:
$ Sudo apt-Get install sun-java6-jdk
Modify the link of javadoc
$ 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
2) Set Environment Variables
$ Emacs ~ /. Bashrc
Add or integrate the PATH variable in. bashrc as follows:
# Java program development/running environment variables
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 java_home;
Export jre_home;
Export classpath;
Home_bin = ~ /Bin/
Export path =$ {path }:$ {java_path }:$ {home_bin };
After saving, synchronously update:
Source ~ /. Bashrc
3) install repo (used to update the android source code)
Create ~ /Bin directory, used to store the repo program, as follows:
$ Cd ~
$ Mkdir Bin
And add it to the environment variable path. It has been added to step 1.
Download the repo script and make it executable:
$ Curl http://android.git.kernel.org/repo> ~ /Bin/Repo
$ Chmod A + x ~ /Bin/Repo
4) repo Initialization
Repo is an android package for git, which simplifies some git operations.
Create a project directory:
$ Mkdir android
$ CD android
Repo Initialization
$ Repo init-u git: // android.git.kernel.org/platform/manifest.git
In this process, enter the name and email address. After the initialization is successful, the following message is displayed:
Repo initialized in/android
In ~ /There will be a hidden directory of. Repo in Android.
5) synchronize source code
$ Repo sync
This step takes a long time
6) Compile the android source code and get ~ /Android/out directory
$ Cd ~ /Andoird
$ Make
This process takes a long time
7) run the compiled Android SDK on the simulator.
After compiling Android, emulator ~ /Android/out/host/linux-x86/bin, ramdisk. IMG, system. IMG and userdata. IMG are ~ /Android/out/target/product/generic
$ Cd ~ /Android/out/host/linux-x86/bin
Add environment variable
$ Emacs ~ /. Bashrc
Add environment variables in. bashrc as follows:
# Java program development/running environment variables
Export android_product_out = ~ /Android/out/target/product/generic
Android_product_out_bin = ~ /Android/out/host/linux-x86/bin
Export path =$ {path }:$ {android_product_out_bin }:: {android_product_out };
Finally, synchronize these changes:
$ Source ~ /. Bashrc
$ Cd ~ /Android/out/target/product/generic
$ Emulator-system. IMG-data userdata. IMG-ramdisk. img
After entering the android desktop, it means the operation is successful.
8) Compilation Module
An application in android can be compiled separately. After compilation, system. IMG must be regenerated.
Run the following command in the source code directory:
$. Build/envsetup. Sh (. There is a space behind it)
There are more commands:
-Croot: Changes directory to the top of the tree.
-M: makes from the top of the tree.
-Mm: builds all of the modules in the current directory.
-Mmm: builds all of the modules in the supplied directories.
-Cgrep: greps on all local C/C ++ files.
-Jgrep: greps on all local java files.
-Resgrep: greps on all local Res/*. XML files.
-Godir: Go to the directory containing a file.
You can add-help to view usage
We can use Mmm to compile the module of the specified directory, for example, compile the contact:
$ Mmm packages/apps/contacts/
Generate two files after editing:
Out/target/product/generic/data/APP/contactstests.apk
Out/target/product/generic/system/APP/contacts.apk
Available
$ Make Snod
Regenerate system. IMG and then run the simulator.
9) Compile the SDK
Directly executing make does not include the make SDK. Make SDK is used to generate the SDK, so that we can use the SDK synchronized with the source code to develop android.
A) Modify/frameworks/base/include/utils/asset. h
Change 'uncompress _ data_max = 1*1024*1024 'to 'uncompress _ data_max = 2*1024*1024'
The reason is that the eclipse compilation project requires a buffer greater than 1.3m;
B) Compile ADT.
I did not perform this step because I do not use eclipse;
C) execute make SDK.
Note that the javadoc version needed here is 1.5, so you need to install the sun-java5-jdk at the same time in step 1
$ Make SDK
Compilation is slow. The compiled SDK is stored in out/host/linux-x86/SDK/, which has a android-sdk_eng.xxx_linux-x86.zip and a android-sdk_eng.xxx_linux-x86 directory. Android-sdk_eng.xxx_linux-x86 is the SDK directory
In fact, when using the mmm command to compile the module, the same will clear the SDK output file, so it is best to move the android-sdk_eng.xxx_linux-x86 out
This SDK will be used for subsequent application development ~ /. Comment out the changes to bashrc and add the following line:
Export path =$ {path }:~ /Android/out/host/linux-x86/sdks/android-sdk_eng.xxx_linux-x86/tools
Replace xxx with a real path;
D) Selection of environment variables and Android tools
Currently, Android tools include:
A. the SDK we downloaded from the Internet, if you have downloaded it (there are many Android tools under tools and IMG images under lib/images)
B. the SDK compiled using make SDK (there are also many Android tools in tools, and IMG images in lib/images)
C. The out directory compiled with make (there are also many Android tools in tools, and IMG images in lib/images)
So what tools should we use and IMG?
First, we generally do not use the option tool and IMG, because it is generally old and the source code is not synchronized. Second, the C option tools and IMG are not used, because these tools and IMG are not classified by the SDK, and tools and configurations cannot be found. In fact, many tools and IMG generated by the make SDK are compiled when make is compiled out of the directory. The make SDK only implements copy.
E) install and configure ADT
Skipped;
F) Create an android Virtual Device
The compiled SDK does not have AVD (Android Virtual Device). You can view it using the android tool:
$ Android list
Create AVD:
$ Android create AVD-T 1-N myavd
You can use Android-help to view the usage of the preceding Command Options. There are some options in the creation, the default is enough
Run the android LIST command to view the location where AVD is stored.
The-AVD myavd or @ myavd option will be added for every running of emulator in the future:
$ Emulator-AVD myavd
10) Compile the Linux kernel Image
A) Prepare the cross-compilation tool chain
The android code tree contains a prebuilt project that contains the cross-compilation tools required for compiling the kernel.
B) Set Environment Variables
$ Emacs ~ /. Bashrc
Add the following two rows:
Export Path = $ path :~ /Android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
Export arch = arm
After saving, synchronize the changes:
$ Source ~ /. Bashrc
C) obtain the appropriate kernel source code
$ Cd ~ /Android
Obtain the kernel source code repository
$ Git clone git: // android.git.kernel.org/kernel/common.git Kernel
$ CD Kernel
$ Git Branch
Display
* Android-2.6.27:
It means that you are now in the branch Android-2.6.27, which is also the default main branch of kernel/common. Git.
Show all head branches:
$ Git branch-
Display
* Android-2.6.27:
Remotes/ORIGIN/head-> origin/Android-2.6.27
Remotes/ORIGIN/Android-2.6.25
Remotes/ORIGIN/Android-2.6.27
Remotes/ORIGIN/Android-2.6.29
Remotes/ORIGIN/Android-goldfsh-2.6.27
Remotes/ORIGIN/Android-goldfsh-2.6.29
We select the latest Android-goldfish-2.6.29, where goldfish is the CPU simulated by the android simulator.
$ Git checkout-B Android-goldfish-2.6.29 origin/Android-goldfish-2.6.29
$ Git Branch
Display
Android 2.6.27
* Android-goldfish-2.6.29
We have already worked on the Android-goldfish-2.6.29 branch.
D) set cross-compilation Parameters
Open the MAKEFILE file in the kernel directory and point cross_compile to the arm-Eabi compiler in the prebuilt you just downloaded.
Cross_compile? = Arm-Eabi-
Set
Ldflags_build_id = $ (patsubst-wl $ (comma) %, % ,\
$ (Call LD-option,-wl $ (comma)-Build-ID ,))
Comment out this line and add an empty ldflags_build_id definition, as shown below:
Ldflags_build_id =
E) Compile the kernel Image
$ Cd ~ /Android/kernel
$ Make goldfish_defconfig
$ Make
F) Test the generated kernel Image
$ Emulator-AVD myavd-kernel ~ /Android/kernel/ARCH/ARM/boot/zimage
This article is based on a large number of resources on the Internet and has no copyright. You can reprint it as needed. By Garnett