这两天着手编译源码的准备工作,在此记录下过程,方便自己备份的同时也希望能对后来者有所帮助。
Attention:本文环境是在ubuntu 11.04下获取并编译android 2.3.3的源码,过程参考了easwy的博文http://easwy.com/blog/archives/compile-android-gingerbread-2-3-1/?以及google官网?http://source.android.com/source/downloading.html?。
官网上的要求信息为:
In general you will need:
Python 2.4 -- 2.7, which you can download from?python.org.
JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from?java.sun.com.
Git 1.5.4 or newer. You can find it at?git-scm.com.
(optional) Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc. Download from?valgrind.org.
另外补充:需要6GB以上磁盘空间,依赖的deb包:flex、bison、gperf、libsdl-dev、libesd0-dev、libwxgtk2.6-dev、build-essential、zip、curl
一、下载前准备工作
首先,准备好所需磁盘空间后,就来安装开发过程中需要的一些开发包,在终端中执行以下命令:
$ sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
在此处,需要注意两点:1.libsdl版本为1.2;2.zlib1g-dev别看错了是1而不是l,当然非手敲的tx就不存在这个问题了。
然后需要安装java环境,直接在终端查看下version:
[email protected]:~$ java -version程序“java”已包含在下列软件包中: * gcj-4.4-jre-headless * gcj-4.5-jre-headless * openjdk-6-jre-headless请尝试:sudo apt-get install <选定的软件包>
输入:sudo apt-get install openjdk-6-jre-headless,安装就ok了,再查看下version:
[email protected]:~$ java -versionjava version "1.6.0_22"OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)OpenJDK Server VM (build 20.0-b11, mixed mode)
jdk就安装好了。
二、下载源码
现在我们已经准备好了android源码开发所需的环境(无错误),下载源码的过程由于Android的源码很是庞大,需要分Android源码和内核两部分获取。内核部分的源码我暂时是不用的,所以这里只下载源码。
1.先新建一个文件夹存放Android目录,并初始化repo:
[email protected]:~$ mkdir Android[email protected]:~$ cd Android[email protected]:~/Android$ mkdir bin[email protected]:~/Android$ cd bin[email protected]:~/Android/bin$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 19731 100 19731 0 0 14034 0 0:00:01 0:00:01 --:--:-- 17157
在这里,几个月前http://android.git.kernel.org/已经无法访问了,很多朋友如果用的是这个源下载站点,就会出现如下情况:
[email protected]:~/Android/bin$ curl http://android.git.kernel.org/repo >repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed100 244 100 244 0 0 75 0 0:00:03 0:00:03 --:--:-- 976
然后在之后的代码初始化时就会出现如下错误:
./bin/repo: 行 1: 未预期的符号 `newline' 附近有语法错误./bin/repo: 行 1: `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'
2.现在继续。建立存放源码目录source,初始化所需的android源码版本,在终端执行如下命令:
[email protected]:~/Android/bin$ sudo chmod a+x repo[email protected]:~/Android/bin$ cd[email protected]:~$ cd Android/source/[email protected]:~/Android/source$ ../bin/repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.3_r1gpg: 钥匙环‘/home/wayne/.repoconfig/gnupg/secring.gpg’已建立gpg: 钥匙环‘/home/wayne/.repoconfig/gnupg/pubring.gpg’已建立gpg: /home/wayne/.repoconfig/gnupg/trustdb.gpg:建立了信任度数据库gpg: 密钥 920F5C65:公钥“Repo Maintainer <[email protected]>”已导入gpg: 合计被处理的数量:1gpg: 已导入:1Get https://android.googlesource.com/tools/reporemote: Counting objects: 1414, doneremote: Finding sources: 100% (78/78)remote: Total 1414 (delta 917), reused 1414 (delta 917)Receiving objects: 100% (1414/1414), 429.88 KiB | 169 KiB/s, done.Resolving deltas: 100% (917/917), done.From https://android.googlesource.com/tools/repo * [new branch] maint -> origin/maint * [new branch] master -> origin/master * [new branch] stable -> origin/stable
...
这样下来之后,会要求输入用户名和邮箱地址,随意写个就ok。
初始化完毕之后会出现:
repo initialized in /home/wayne/Android/source
现在完成初始化之后便可以下载了,在终端执行如下命令,开始下载:
[email protected]:~/Android/source$ ../bin/repo sync
下载全部的源码需要很长时间,现在正在经历漫长的等待……
过程中时常看一下,也许会出错而中断:
error: Exited sync due to fetch errors
遇到这些问题时,重新执行一遍../bin/repo sync就ok。
?