Compile Android Operating System Program
时间:2010-09-24 来源:光与影的交替
1. Install java jdk 5
Open /etc/apt/sources.list with a text editor like gedit:
sudo gedit /etc/apt/sources.list
Add the following lines to the end of the file then save it and close:
## For sun-java5-jdk
deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse
Update the packages lists and install sun-java5-jdk:
sudo apt-get update
sudo apt-get install sun-java5-jdk
2. Setup the environment variables for Java
sudo gedit ~/.bashrc
add the following to the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
export JRE_HOME=${JAVA_HOME}/jre
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export ANDROID_JAVA_HOME=${JAVA_HOME}
export HOME_BIN=~/bin
export PATH=${PATH}:${JAVA_PATH}:${HOME_BIN}
export CLASSPATH=.:$CLASSPATH:${JAVA_HOME}/lib:${JRE_HOME}/lib
close the file, and update the list with the following command:
source ~/.bashrc
to check the variables, use echo command or env, for example:
echo $JAVA_HOME
env
To alter the javadoc link to java 5 version, use the following command:
cd /etc/alternatives
sudo rm javadoc.1.gz
sudo rm javadoc
sudo ln -s /usr/lib/jvm/java-1.5.0-sun/man/man1/javadoc.1.gz javadoc.1.gz
sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/javadoc javadoc
if something is still wrong, you can also change the javac/java link to java 5 version:
sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/javac javac
sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/java java
If you install more than one java version, use can use the following command to choose the right one.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-1.5.0-sun/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-1.5.0-sun/bin/javac 300
sudo update-alternatives --config java
To see the java version, use:
java -version
3. Install necessary tools
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
If something is wrong, you may find the following commands helpful:
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.6
4. Install repo ( to update android source)
cd ~ && mkdir bin
curl http://android.git.kernel.org/repo >~/bin/repo
chmod a+x ~/bin/repo
Then initialize repo
mkdir android && cd android
repo init -u git://android.git.kernel.org/platform/manifest.git
During this process, you will be asked to enter your name and email.
If it succeed, it will show like:
repo initialized in /android
5. Get the source
Use the following cmd to get the code, it will take very very long time, so you can go and have a snap.
repo sync
6. Compile android source code
You will get the output files in ~/android/out directory
cd ~/andoird
make
well, another snap.
7. run img using emulator
emulator is under ~/android/out/host/linux-x86/bin,
ramdisk.img, system.img and userdata.img are under ~/android/out/target/product/generic
add the following variables:
export ANDROID_PRODUCT_OUT=~/android/out/target/product/generic
ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/binexport PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};
update:
source ~/.bashrc
then, try to use emulator to load the img
cd ~/android/out/target/product/generic
emulator -system system.img -data userdata.img -ramdisk ramdisk.img
if you see the android GUI, congratulations!
8. make a rom
zip -r update.zip .
sign the file (under java 6 version)
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JRE_HOME=${JAVA_HOME}/jre
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
sudo update-alternatives --config java
java -version
If you are using java 6 now, put the autosign.jar under the folder
java -jar autosign.jar update.zip update_signed.zip
Reference: http://hi.baidu.com/garnetttt/blog/item/13426d222f72b3ae4623e8f3.html