由于下载的时候折腾得有点久,所以写下来跟大家交流一下。
我的下载环境是虚拟机ubuntu11.10,下面是我下载源码的整个过程:
基本是根据http://source.android.com/source/downloading.html的提示进行
To install, initialize, and configure Repo, follow these steps:
Make sure you have a bin/ directory in your home directory, and that it is included in your path:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
在下载之前,记得查看是否已经装了git
如果没有的话,可以通过一下命令安装:
$ sudo apt-get install git
$ sudo apt-get install git-core
确保已经安装git之后,再进行下面的操作。
Download the Repo script and ensure it is executable:
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
After installing Repo, set up your client to access the android source repository:
Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
$ repo init -u https://android.googlesource.com/platform/manifest
To check out a branch other than "master", specify it with -b:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
Getting the files
To pull down files to your working directory from the repositories as specified in the default manifest, run
$ repo sync
整个过程下来,估计很多人都是卡在下面的命令那里,我一开始就卡在这里,呵呵。
$ repo init -u https://android.googlesource.com/platform/manifest
出现的错误一般如下:
1 Exception in thread Thread-3:
2 Traceback (most recent call last):
3 File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
4 self.run()
5 File "/usr/lib/python2.6/threading.py", line 484, in run
6 self.__target(*self.__args, **self.__kwargs)
7 File "/home/haili/android-4.0.4_r1.2/.repo/repo/subcmds/sync.py", line 200, in _FetchHelper
8 clone_bundle=not opt.no_clone_bundle)
9 File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 978, in Sync_NetworkHalf
10 and self._ApplyCloneBundle(initial=is_new, quiet=quiet):
11 File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1519, in _ApplyCloneBundle
12 exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet)
13 File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1583, in _FetchBundle
14 raise DownloadError('%s: %s ' % (req.get_host(), str(e)))
15 DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out>
16 ...
其实关于这个文档google有给出解决方法,英文好的直接看文档就明白了。
大概的解决方法如下:
1. 浏览器登录https://android.googlesource.com/new-password,并用gmail帐号登录;
2. 点击网页上的“允许访问”,得到类似:
machine android.googlesource.com login git-<userName>.gmail.com password <password>
machine android-review.googlesource.com login git-<userName>.gmail.com password <password>
的信息。
3. 把上面那段信息(<userName>和<password>用自己得到的真实信息)追加到~/.netrc文件结尾;(补充一下,这里直接用编辑器打开就行了,如 $vi ~/.netrc,关于这个文件网上有很多人问在哪里。)
4. 下载地址的URI更改为https://android.googlesource.com/a/platform/manifest(中间加上了“/a”)。
然后按照官网描述的正常步骤操作,即可拉下Android源码。
官方的说法是:因为访问基本是匿名的,为了防止连接过多,对同一IP地址的连接数做了一定的限制。看来是用gmail帐号进行认证。
这样的话,在公司网络内或者用虚拟机下载的话,会经常遇到这问题。