Android Source Code Download
TOP Website
android 的最新源代碼下載的官方網站是:http://source.android.com
源代碼的下載說明頁面是:http://source.android.com/download (現在貌似用還用不了)
現在的網站是http://git.android.com
TOP Create Directory
在HOME(/home/justin)目錄下創建如下目錄結構:
/home/justin/android :
總計 36
drwxr-xr-x 7 justin justin 4096 01-15 10:34 .
drwxr-xr-x 58 justin justin 12288 01-15 10:39 ..
drwxr-xr-x 2 justin justin 4096 01-15 10:34 applications
drwxr-xr-x 2 justin justin 4096 01-15 10:33 downloads
drwxr-xr-x 2 justin justin 4096 01-15 12:34 bin
drwxr-xr-x 2 justin justin 4096 01-15 10:33 sdk
drwxr-xr-x 2 justin justin 4096 01-15 10:33 src
drwxr-xr-x 2 justin justin 4096 01-15 10:34 tools
將該目錄添加到PATH環境變量:
export PATH=$HOME/android/bin:$PATH
如果需要反復使用,需要將這一行加入~/.bashrc啟動腳本中
TOP Donwload Tool Chain
TOP Git
Git的版本在1.5.4之上
sudo apt-get install git-core
TOP Proxy
安裝代理軟件:
apt-get install connect-proxy
Repo
repo是包裝了git命令的python
腳本:
curl http://android.git.kernel.org/repo > ~/android/bin/repo
網關內部需要設置curl代理
假設網段的(http)代理為:wwwgate.freeshell.net:8080
curl --proxy wwwgate.freeshell.net:8080 http://android.git.kernel.org/repo > ~/android/bin/repo
加上可執行權限
chmod a+x ~/android/bin/repo
Python
Python的版本在2.4之上
sudo apt-get install python
JDK 1.6
在下列地址下載: http://java.sun.com/javase/downloads 解壓得到如下文件: ~/android /downloads/jdk-6u11-linux-i586.bin
cd ~/android/downloads
chmode a+x jdk-6u11-linux-i586.bin
運行這個可執行文件, 將生成的目錄jdk1.6.0_11拷貝到/usr/local/下
將下列環境變量加入~/.bashrc:
export PATH=/usr/local/jdk1.6.0_11/bin:$PATH
export JAVA_HOME=/usr/local/jdk1.6.0_11
export ANDROID_JAVA_HOME=$JAVA_HOME
tools
sudo apt-get install gcc g++
sudo apt-get install flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.6-dev /
build-essential zip curl libncurses5-dev zlib1g-dev valgrind libreadline5-dev
如果因為缺少X11/Xatom.h和X11/Xlib.h導致的build失敗,
可以安裝如下包:
sudo apt-get install x11proto-core-dev # provides Xatom.h
sudo apt-get install libx11-dev # provides Xlib.h
交叉編譯環境
android emulator 默認的目標代碼是arm7的代碼。如果需要將目標代碼移植到其他版本的arm平台上去,需要重新配置相應的交叉編譯環境。
TOP 下載Android平台源代碼
1. 初始化要下載的文件列表:
cd ~/android/src
repo init -u git://android.git.kernel.org/platform/manifest.git
如果想檢出除master外其他分支上的代碼可以用-b選項:
cd ~/android/src
repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
2. 配置git帳戶
git config --global user.email "xxxxx@xxxxxxx"
git config --global user.name "xxxxxx"
3. 同步文件列表:
repo sync
在第一次下載全部代碼完成后,可以按模塊更新子項目的代碼:
repo sync project-path
其中的project-path可以在src/.repo/manifests/default.xml中找到:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="korg"
fetch="git://android.git.kernel.org/"
review="review.source.android.com" />
<default revision="master" remote="korg" />
<project path="build" name="platform/build">
<copyfile src="http://blog.soso.com/qz.q/core/root.mk" dest="Makefile" />
</project>
<project path="kernel"
name="kernel/common"
revision="refs/heads/android-2.6.27" />
<project path="bionic" name="platform/bionic" />
<project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" />
<project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" />
<project path="bootable/recovery" name="platform/bootable/recovery" />
... ...
在網關內部使用需要設置代理:
新建如下文件: #!/bin/sh
# /home/justin/android/bin/socks-gw.sh
# This script connects to a HTTP proxy using connect.c
connect -H wwwgate.freeshell.net:8080 #!/bin/sh
# /home/justin/android/bin/socks-ssh.sh
ssh -o ProxyCommand="/home/justin/android/bin/socks-gw.sh %h %p" $@
增加這兩個文件的可執行權限:
chmod a+x /home/justin/android/bin/socks-ssh.sh
chmod a+x /home/justin/android/bin/socks-gw.sh
可以將所有代理的環境變量放在:
#!/bin/sh
# /home/justin/proxy.sh
# http proxy setting
export HTTP_PROXY=http://wwwgate.freeshell.net:8080
export http_proxy=$HTTP_PROXY
# set git to use ssh over http proxy
export GIT_SSH="/home/justin/android/bin/socks-ssh.sh"
export GIT_PROXY_COMMAND="/home/justin/android/bin/socks- gw.sh"
需要的時候運行:
. ~/proxy.sh
編譯Android平台以及SDK
完全編譯
編譯映像
cd ~/android/src
make
映像編譯成功后會在目錄~/android/src/out/target/product/generic
下產生一些image文件
ramdisk.img system.img userdata.img android -info.txt
驗證,運行這些模塊:
export ANDROID_PRODUCT_OUT=/home/justin/android/src/out/t arget/product/generic
cd out/host/linux-x86/bin
./emulator
此時可能出現如下錯誤
SDL init failure, reason is: No available video device
需要設置下圖形server
# export DISPLAY=:0
SDK編譯
在做完一次完全編譯后,就可以build SDK了。
make sdk
注意:如果需要build SDK,需要安裝sun-java5-jdk, 而不是sun-java6-jdk,否則會出現如下錯誤:
build/core/product_config.mk:207: WARNING: adding test OTA key
============================================
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=
============================================
Combining NOTICE files: out/target/product/generic/obj/NOTICE.txt
Finding NOTICE files: out/host/linux-x86/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/host/linux-x86/obj/NOTICE.txt
out/target/product/generic/generic-img-eng.justin. zip
SDK buildinfo: out/target/product/generic/sdk/sdk-build.prop
Docs droiddoc: out/target/common/docs/dx
此時,可以考慮重新安裝sun jdk5, 或者直接從http://java.sun.com/javase/downloads
下載到~/android
/downloads/jdk-1_5_0_17-linux-i586.bin
sudo apt-get install sun-java5-jdk
並設置相應的.bashrc命令。
sdk編譯成功后會在~/android /src /out/host/linux-x86/sdk/ 生成sdk的文件目錄和壓縮包:
android -sdk_eng.justin_linux-x86
android -sdk_eng.justin_linux-x86.zip
並在~/android /src /out/target/product/generic(generic是默認的產品名)下打包所有的映像文件:
generic-img-eng.justin.zip
生成的SDK目錄結構為:
/home/justin/android/src/out/host/linux-x86/sdk/an droid-sdk_eng.justin_linux-x86:
總計 32
drwxrwx--- 6 justin justin 4096 02-13 17:06 .
drwxr-x--- 3 justin justin 4096 02-13 17:09 ..
drwxrwx--- 2 justin justin 4096 02-13 17:06 add-ons
drwxrwx--- 14 justin justin 4096 02-13 17:06 docs
-rw-rw---- 1 justin justin 172 02-13 17:08 documentation.html
drwxrwx--- 3 justin justin 4096 02-13 17:06 platforms
-rw-rw---- 1 justin justin 225 02-13 17:08 RELEASE_NOTES.txt
drwxrwx--- 3 justin justin 4096 02-13 17:08 tools
安裝生成的SDK只需要在.bashrc中增加:
export PATH=$PATH:/home/justin/android/src/out/host/linux -x86/sdk/android-sdk_eng.justin_linux-x86/tools
為了使用方便,將生成的SDK目錄鏈結至~/android
/sdk:
ln -sf /home/justin/android/src/out/host/linux-x86/sdk/an droid-sdk_eng.justin_linux-x86/tools /
~/android/sdk
模塊編譯
在src目錄執行:
cd ~/android/src
. build/envsetup.sh
envsetup.sh 提供了一些的bash函數定義,當運行了envsetup.sh后就可以使用help
命令來查看:
help
得到這些命令的幫助信息:
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- 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.
Look at the source to view more functions. The complete list is:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant croot findmakefile gd
bclient get_abs_build_var getbugreports get_build_var getprebuilt gettop help isviewserverstarted jgrep lunch m mm mmm pid
printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoke
test startviewserver stopviewserver tapas tracedmdump
其中對模塊的編譯有幫助的是tapas、m、mm、mmm這幾個命令。
1.tapas - 以交互方式設置build環境,以下是運行效果:
tapas
第一步,選擇目標設備:
Build for the simulator or the device?
1. Device
2. Simulator
Which would you like? [1]
第二步,選擇目標代碼格式:Build type choices are:
1. release
2. debug
Which would you like? [1]
第三步,選擇產品平台:
Product choices are:
1. emulator
2. generic
3. sim
You can also type the name of a product if you know it.
Which would you like? [generic]
第四步,在選用參數下構建平台。
2. 獨立模塊的構件命令
* 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.
其中mmm后面要跟模塊的根目錄,不是所有的目錄下都有子模塊,那些含有Android.mk文件目錄才是模塊的根目錄,模塊名可以從 Android.mk的LOCAL_MODULE或者LOCAL_PACKAGE_NAME變量中得到。
單獨編譯某模塊,需要在mmm后面指定模塊路徑,例如編譯application中的Contacts:
mmm packages/apps/Contacts/
或者在src目錄下直接運行make module name :
cd ~/android/src
make Contacts
TOP 增量編譯的步驟
1. 修改代碼
2. 編譯所修改的代碼所在模塊,例如:
cd ~/android/src
mmm packages/apps/Contacts
3. 在~/android /src 中運行:
cd ~/android/src
make snod
該命令生成一個新的系統映像system.img
4.將這個系統映像拷貝至sdk下:
cd ~/android/src
cp out/target/product/generic/system.img /
out/host/linux-x86/sdk/android-sdk_eng.justin_linu x-x86/tools/lib/images/
5. 刪除程序遺留的數據:
out/host/linux-x86/sdk/android-sdk_eng.justin_linu x-x86/tools/emulator -wipe-data
制作文件系統
Usually the Android uses YAFFS as rootfs and uses the mtd device as storage media, the bad blocks in the mtd device seldom cause YAFFS file system to work abnormally. if the Android uses NFS as the rootfs, there will not exist such problem. So here is the solution to use NFS as the rootfs of Android.
1. Setup host machine as NFS server (I will use ubuntu 8.0.4 as an example.).
$ sudo apt-get install nfs-kernel-server portmap
$ sudo mkdir /nfsroot
$ sudo vim /etc/exports
Add one line in /etc/exports,
/nfsroot 192.168.1.101(rw,no_root_squash ,sync)
Then restart NFS server.
$ sudo /etc/init.d/nfs-kernel-server restart Here setups an NFS server which exports /nfsroot directory only to 192.168.1.101(Which is the default IP address of Android eth0).
2. Build a Linux kernel image to use NFS as rootfs.
$make menuconfig
Modify the default setup. In "general setup" section, uncheck the "initial RAM filesystem and RAM disk(initramfs/initrd) support". In "file systems" section, check the "Network File Systems" and mark it as kernel built-in. In "boot options" section, add the kernel parameter "root=/dev/nfs nfsroot=192.168.1.100:/nfsroot init=/init ". 192.168.1.100 is the IP address of host machine running NFS server.
3. Modify init program.
To make log system work, in the device/system/init modify the device.c by change the statement '!strncmp(uevent->path,"/class/misc/",12) && !strncmp(name, "log_", 4) to '!strncmp(name, "log_", 4) '.
4. Modify init.rc config file.
Comment out below statements
mount rootfs rootfs /ro remount
mount yaffs mtd@system /system
mount yaffs2 mtd@system /system ro remout
mount yaffs2 mtd@userdata /data nosuid nodev
mount yaffs2 mtd@cache /cache nosuid nodev
5. Add the user id and group id used by android on the NFS server.
Android does not use /ect/passwd file to record the user name and user id, it uses a fixed method to map the user name to user id through the head file device/include/private/android_filesystem_config.h , e.g. the user "system" has the user id of 1000.
So to correctly set the file ownership(owner and group), the NFS server should have these users with correct user IDs. Such as system(1000). For ubuntu, you can call like this.
$sudo userdd -u 1000 android_system
6. This step is not necessary. It only allows you to display a user name in the develop machine. 6. Prepare the rootfs.
Assume the built output of device lies in device/out/target/product/***/, which is called $OUTPUTDIR later. Do the follwings:
$cp -rf $OUTPUTDIR/root/* /nfsroot
$cp -rf $OUTPUTDIR/system /nfsroot
$cp -rf $OUTPUTDIR/data /nfsroo
參考
http://mmmyddd.freeshell.net/wiki/android/build.ht ml#top