参考网站:
http://developer.android.com/sdk/index.html
http://source.android.com/source/
本人在Ubuntu 10.04 LTS系统 32位机上安装编译Android2.3源码,其步骤和注意事项如下:
1.安装JDK6
对于Android2.3系统,不要安装JDK5,应该安装最新的JDK6。
如果安装了JDK6,Android会自动按64位编译,如果系统是32位的,会有编译错误,后面会说如何修改这个错误。
$ sudo vim /etc/apt/sources.list
添加deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse到文件末尾
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
出现如下信息,选择Y.开始安装
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
gsfonts-x11 java-common odbcinst odbcinst1debian1 sun-java6-bin
sun-java6-jre unixodbc
Suggested packages:
default-jre equivs sun-java6-demo sun-java6-doc sun-java6-source
sun-java6-fonts sun-java6-plugin ia32-sun-java6-plugin ttf-kochi-gothic
ttf-sazanami-gothic ttf-kochi-mincho ttf-sazanami-mincho ttf-wqy-zenhei
libmyodbc odbc-postgresql tdsodbc unixodbc-bin
The following NEW packages will be installed:
gsfonts-x11 java-common odbcinst odbcinst1debian1 sun-java6-bin
sun-java6-jdk sun-java6-jre unixodbc
0 upgraded, 8 newly installed, 0 to remove and 219 not upgraded.
Need to get 43.6MB of archives.
After this operation, 131MB of additional disk space will be used.
Do you want to continue [Y/n]?
中途会出现menu_config界面,通过“TAB”键选择YES继续,直到安装完成
最后会发现安装在:/usr/lib/jvm/java-6-sun/目录下面
安装完后,需要手动设置JAVA_HOME, JRE_HOME, CLASS_PATH为JDK6的安装路径。
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}:${JRE_HOME}:${HOME_BIN};
2.安装开发过程中需要的一此开发包,命令如下所示:
$ sudo apt-get install git-core gnupg valgrind flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
3.安装Repo
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
刚开始执行curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo会出现如下错误:
root@ubuntu:~ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
--2013-04-21 04:30:42-- https://dl-ssl.google.com/dl/googlesource/git-repo/repo
Resolving dl-ssl.google.com... 74.125.128.91, 74.125.128.93, 74.125.128.136, ...
Connecting to dl-ssl.google.com|74.125.128.91|:443... failed: Connection refused.
Connecting to dl-ssl.google.com|74.125.128.93|:443... failed: Connection timed out.
Connecting to dl-ssl.google.com|74.125.128.136|:443... failed: Connection timed out.
Connecting to dl-ssl.google.com|74.125.128.190|:443... failed: Connection timed out.
Connecting to dl-ssl.google.com|2404:6800:4005:c00::5d|:443... failed: Network is unreachable.
解决办法:
打开 gedit /etc/hosts
添加如下红色加粗内容:
127.0.0.1localhost
127.0.1.1 ubuntu
74.125.237.1 dl-ssl.google.com
然后重复上述操作,出一如下,说明下载成功
root@ubuntu:~#curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
--2013-04-21 05:52:13-- https://dl-ssl.google.com/dl/googlesource/git-repo/repo
Resolving dl-ssl.google.com... 74.125.237.1
Connecting to dl-ssl.google.com|74.125.237.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22889 (22K) [application/octet-stream]
Saving to: `repo'
100%[==============================================================================================================================>] 22,889 95.1K/s in 0.2s
2013-04-21 05:52:15 (95.1 KB/s) - `repo' saved [22889/22889]
4.下载android源码
USER-NAME@MACHINE-NAME:~$ mkdir Android
USER-NAME@MACHINE-NAME:~$ cd Android
USER-NAME@MACHINE-NAME:~/Android$
repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1 USER-NAME@MACHINE-NAME:~/Android$ repo sync
$ mkdir ~/bin
$ export PATH=~/bin:$PATH
$ curl http://Android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
在执行repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1
时出现如下错误:
fatal: git 1.7.2 or later required
解决办法:
执行如下操作:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
重新执行repo init -uhttps://android.googlesource.com/platform/manifest -b android-2.3.1_r1又出现如下错误
error.GitError: manifests var:
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@ubuntu.(none)')
根据提示,如下执行:
root@ubuntu:/opt/work/android/source# git config --global user.email "[email protected]"
root@ubuntu:/opt/work/android/source# git config --global user.name "qiuyigui"
重新执行repo init -uhttps://android.googlesource.com/platform/manifest -b android-2.3.1_r1出现如下提示,选择y
Your identity is: qiuyigui <[email protected]>
If you want to change this, please re-run 'repo init' with --config-name
Testing colorized output (for 'repo diff', 'repo status'):
black red green yellow blue magenta cyan white
bold dim ul reverse
Enable color display in this user account (y/N)? y
这回初始化成功了,最后会显示:
repo has been initialized in /opt/work/android/source
输入:repo sync开始下载源代码
error: Failed to connect to 2404:6800:4008:c00::52: Network is unreachable while accessing https://android.googlesource.com/platform/manifest/info/refs?service=git-upload-pack
fatal: HTTP request failed
error: Failed to connect to 2404:6800:4008:c00::52: Network is unreachable while accessing https://android.googlesource.com/platform/manifest/info/refs?service=git-upload-pack
fatal: HTTP request failed
curl: (7) Failed to connect to 2404:6800:4008:c00::52: Network is unreachable
curl: (7) Failed to connect to 2404:6800:4008:c00::52: Network is unreachable
curl: (7) Failed to connect to 2404:6800:4008:c00::52: Network is unreachable
curl: (7) Failed to connect to 2404:6800:4008:c00::52: Network is unreachable
error: Failed to connect to 2404:6800:4008:c00::52: Network is unreachable while accessing https://android.googlesource.com/platform/bootable/bootloader/legacy/info/refs?service=git-upload-pack
fatal: HTTP request failed
error: Failed to connect to 2404:6800:4008:c00::52: Network is unreachable while accessing https://android.googlesource.com/platform/bootable/recovery/info/refs?service=git-upload-pack
fatal: HTTP request failed
解决办法:
1.浏览器登录https://android.googlesource.com/new-password,并用gmail帐号登录(去谷歌注册);
2.点击网页上的“允许访问”,得到类似
1 machine android.googlesource.com login git-<userName>.gmail.com password <password> 2 machine android-review.googlesource.com login git-<userName>.gmail.com password <password>
3.把上面那段信息追加到~/.netrc文件结尾(请检查当前用户的权限,如果不存在此文件则自己新建一个);
4.下载地址的URI更改为https://android.googlesource.com/a/platform/manifest(中间加上了“/a”)。
5. repo init -u https://android.googlesource.com/a/platform/manifest -b android-2.3.3_r1
6. repo sync
即可下Android源码。
官方的说法是:因为访问基本是匿名的,为了防止连接过多(指内网/虚拟机),对同一IP地址的连接数做了一定的限制。看来是用gmail帐号进行认证。
这样的话,在公司网络内或者用虚拟机下载的话,会经常遇到这问题。
下载期间经常会出现如下错误:
出现这样情况时,等回到命令提示符时,继续输入(android支持断点续传):
repo sync
重复上述操作
最后出现如下显示,表明下载成功了:
这一步持续时间很长,整个源码+SDK共5G左右,我是下载了一个晚上才搞定,网速不给力啊。。。
5.编译Android2.3
先export Android_JAVA_HOME=$JAVA_HOME
$ cd ~/Android2.3
$ make -j4
在make的时候会提示出错:
(一)
************************************************************
You are attempting to build on a 32-bit system.
Only 64-bit build environments are supported beyond froyo/2.2.
************************************************************
因为Android2.3默认是64位的系统上编译,需要手动修改build/core/main.mk,把这个判断部分注释掉:
#ifneq (64,$(findstring 64,$(build_arch)))
#$(warning ************************************************************)
#$(warning You are attempting to build on a 32-bit system.)
#$(warning Only 64-bit build environments are supported beyond froyo/2.2.)
#$(warning ************************************************************)
#$(error stop)
#endif
(二)
重新make,如果是安装了JDK6版本,会又报错:
Docs droiddoc: out/target/common/docs/api-stubs
Could not load ‘clearsilver-jni’
java.library.path = out/host/linux-x86/lib
make: *** [out/target/common/docs/api-stubs-timestamp] Error 45
make: *** Waiting for unfinished jobs….
Could not load ‘clearsilver-jni’
java.library.path = out/host/linux-x86/lib
make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45
这是由于clearsilver在编译时如果检测到使用Java JDK 6,就使用64位编译,因为Google的一个员工更新了几个文件。这里可以看到详细的修改记录:http://android.git.kernel.org/?p=platform/external/clearsilver.git;a=commitdiff;h=d36910a8110d8377b22301274d2b5131a732a72b
修改这几个文件,该回到32位编译环境即可:
external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk
把编译选项-m64改成-m32即可
重新make,大概不到一个小时就make完了。