一 前言
学习一门技术最好的方式莫过于阅读它的源代码,正如Linux鼻祖的经典名言:read the fucking source code .. 英语不太好,大概意思是:去读那些操蛋的源代码吧!而Android提供了大量的源代码给我们学习,所以,我们不去阅读下,真是暴殄天物!
so... 今天这篇文章的话,就是讨论怎么在windows环境下,下载,编译android源代码。。。
我的环境是windows xp ....
二 VMware虚拟机
如上所述,我们用的是windows操作环境。但是android源代码是用git工具来管理的,一般在linux环境下来同步,所以,第一步,我们需要安装linux环境。这里的话,我们选择VMware来运行linux虚拟机。
VMware的话,我选择VMWare 7.1.4,版本尽量新点,听说低版本的VMware网络支持不是很好,我们下载源代码,网络不好是不行滴。。。
三 ubuntu安装
对于Linux环境,我选择的是ubuntu, 版本是ubuntu-11.04-desktop-i386.iso
然后还有注意点的是设置虚拟机的内存和硬盘,内存根据自己电脑配置设置,我3G内存,分配了1G给虚拟机。硬盘的话,我分配了30G,因为担心下载编译后,空间不够。
四 配置环境
一路无语,等你的ubuntu启动完毕之后,ctrl + alt + T 打开命令行, 执行下列命令
1. USER-NAME@MACHINE-NAME:~$ sudo apt-get install git-core gnupg
2. 安装JDK。在Ubuntu上执行以下命令:
USER-NAME@MACHINE-NAME:~$ sudo add-apt-repository ppa:ferramroberto/java
USER-NAME@MACHINE-NAME:~$ sudo apt-get update
USER-NAME@MACHINE-NAME:~$ sudo apt-get install sun-java6-jre sun-java6-plugin
USER-NAME@MACHINE-NAME:~$ sudo apt-get install sun-java6-jdk
3. 依赖的其它包。在Ubuntu上执行以下命令:
USER-NAME@MACHINE-NAME:~$ sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
4. 调试工具。在Ubuntu上执行以下命令:
USER-NAME@MACHINE-NAME:~$ sudo apt-get install valgrind
5. 安装curl ,执行以下命令:
sudo apt-get install curl
有个时候,可能你的ubuntu没有配置源,导致安装不成功,我们可以配置下。
命令:sudo gedit /etc/apt/sources.list
然后把下面的源添加进文件,保存
复制内容到剪贴板
代码:
deb http://tw.archive.ubuntu.com/ubuntu/ oneiric main universe restricted multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ oneiric main universe restricted multiverse
deb http://tw.archive.ubuntu.com/ubuntu/ oneiric-security universe main multiverse restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ oneiric-security universe main multiverse restricted
deb http://tw.archive.ubuntu.com/ubuntu/ oneiric-updates universe main multiverse restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ oneiric-updates universe main multiverse restricted
#网易 Ubuntu 11.10 源(速度很快)
deb http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
#骨头源,骨头源是bones7456架设的一个Ubuntu源 ,提供ubuntu,deepin
deb http://ubuntu.srt.cn/ubuntu/ oneiric main universe restricted multiverse
deb-src http://ubuntu.srt.cn/ubuntu/ oneiric main universe restricted multiverse
deb http://ubuntu.srt.cn/ubuntu/ oneiric-security universe main multiverse restricted
deb-src http://ubuntu.srt.cn/ubuntu/ oneiric-security universe main multiverse restricted
deb http://ubuntu.srt.cn/ubuntu/ oneiric-updates universe main multiverse restricted
deb http://ubuntu.srt.cn/ubuntu/ oneiric-proposed universe main multiverse restricted
deb-src http://ubuntu.srt.cn/ubuntu/ oneiric-proposed universe main multiverse restricted
deb http://ubuntu.srt.cn/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://ubuntu.srt.cn/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://ubuntu.srt.cn/ubuntu/ oneiric-updates universe main multiverse restricted
#mirror.lupaworld.com的源,速度很快
deb http://mirror.lupaworld.com/ubuntu/archive/ oneiric main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu/archive/ oneiric-security main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu/archive/ oneiric-updates main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu/archive/ oneiric-backports main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu/ubuntu-cn/ oneiric main restricted universe multiverse
#这里你也可以直接使用更快速的ubuntu.cn99.com的源(推荐):
deb http://ubuntu.cn99.com/ubuntu/ oneiric main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ oneiric-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ oneiric-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ oneiric-backports main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu-cn/ oneiric main restricted universe multiverse
然后执行 sudo apt-get update 进行更新。。
6. 下载repo,执行下面命令
a. mkdir ~/bin
b. PATH=~/bin:$PATH
c. curl
https://dl-ssl.google.com/dl/googlesource/git-repo/repo
> ~/bin/repo
d. chmod 777 ~/bin/repo
上面这个命令
curl
https://dl-ssl.google.com/dl/googlesource/git-repo/repo
> ~/bin/repo
可能会执行不成功,经常被河蟹,
下面这个也许可以
curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo"> ~/bin/repo
7. 创建源代码目录,并进入
mkdir ~/android_prj
cd ~/android_prj
8. 初始化, 我这里下载的是android2.3的代码,这个版本的代码非常具有代表性,和2.2相比,做了很多改动。。
repo init -u git://android.git.kernel.org/platform/manifest.git -b gingerbread
特殊说明:执行上面一行命令后失败原因如下:
curl: (6) Couldn't resolve host 'android.git.kernel.org'
原因是因为android.git.kernel.org网站被黑了,所以无法从该网站下载repo和android源代码了。
因此我们只能想办法从其他地方下载了.
我们可以从https://www.codeaurora.org/网站下载android源码。
具体方法如下:
下载repo并设置环境变量
$ curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo"> ~/bin/repo
$ chmod a+x ~/bin/repo
$ PATH=~/bin:$PATH
下载android源码
$ mkdir WORKING_DIRECTORY
$cd WORKING_DIRECTORY
$ repo init -u git://codeaurora.org/platform/manifest.git -b gingerbread
$ repo sync
PS: repo只是一个脚本工具。你可以从任何地方下载repo工具,例如
http://code.google.com/p/git-repo/
但是如何要下载android源代码的话,需要把repo文件打开,把文件开头的
REPO_URL='git://android.git.kernel.org/tools/repo.git'
的这个地址换成其他可以下载源代码的地址久可以了,上面下载的repo就是把
REPO_URL='git://android.git.kernel.org/tools/repo.git'
替换成
REPO_URL='git://codeaurora.org/tools/repo.git'
9. repo sync 开始同步代码,我同步了一个晚上,听说有的同步了两天两夜。。
五 编译代码
1 . build/envsetup.sh 注意前面有个空格和点号
2. choosecombo 下面的参数默认就可。。
3. make开始编译。
如果,出现了如下界面,则说明,你编译完成了。。。