linux下载android源码的若干问题

本周开始看《深入理解android卷一》这本书,在第一章下载android源码这一部分遇到过比较多的问题,纠结了很久才下到android源码。

现将其中遇到的问题归纳如下:

在书中,下载anroid的代码如下:

apt-get install git-core curl #先下载这两个工具 mkdir -p /develop/download-froyo #在根目录下建立develop和download-froyo这两个目录 cd ~/develop/download-froyo #进入这个目录 crul http://Android.git.kernel.org/repo>./repo #从源码下载repo脚本,该脚本是google为了方便源码下载而提供的,通过该脚本可下载整套源码 chmod a+x repo #设置该脚本为可执行 ./repo init -u git://android.git.kernel.org/platform/manifest.git -b froyo #初始化git库 ./repo sync #下载源码,大约2GB,如果网上快,估计也要2个多小时 这个代码过于古老,现在已经没法用了。我们到谷歌android下载的主页可以看到新的下载代码。

mkdir ~/bin PATH=~/bin:$PATH curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo chmod a+x ~/bin/repo mkdir WORKING_DIRECTORY cd WORKING_DIRECTORY repo init -u https://android.googlesource.com/platform/manifest repo sync 这个代码可以下载到最新的android代码。

但是,如果你使用虚拟机下载(我使用的是ubuntu虚拟机)时,任然会出现问题。

问题1

但是在repo 初始化过程中却遇到一个问题
/root/bin/repo line 1: syntax error near unexpected token `newline'
以前也下过源码,却没有碰到过这种问题
经过测试,重新下载
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ repo init -u https://android.googlesource.com/platform/manifest
$ repo sync
注意这里是https ,不是http
开始写成http的时候就产生了上面的问题

问题2

报错

Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 484, in run self.__target(*self.__args, **self.__kwargs) File "/home/haili/android-4.0.4_r1.2/.repo/repo/subcmds/sync.py", line 200, in _FetchHelper clone_bundle=not opt.no_clone_bundle) File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 978, in Sync_NetworkHalf and self._ApplyCloneBundle(initial=is_new, quiet=quiet): File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1519, in _ApplyCloneBundle exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet) File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1583, in _FetchBundle raise DownloadError('%s: %s ' % (req.get_host(), str(e))) DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out> 看这出错很莫名,Python是正确安装了的,版本也是要求的。其实官网(http://source.android.com/source/downloading.html)有段说明,如果认真执行就可解决。
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文件结尾;
4. 下载地址的URI更改为https://android.googlesource.com/a/platform/manifest(中间加上了“/a”)。
然后按照官网描述的正常步骤操作,即可拉下Android源码。
官方的说法是:因为访问基本是匿名的,为了防止连接过多,对同一IP地址的连接数做了一定的限制。看来是用gmail帐号进行认证。这样的话,在公司网络内或者用虚拟机下载的话,会经常遇到这问题。
问题3

报错

error: git was compiled without libcurl support
这一部分主要git版本太低引起的,如果是1.7以上版本则应该没有此错误。

其解决方法为:

The solution is to add backports.debian.org/debian-backports [A] to your /etc/apt/sources.list like this:
# vi /etc/apt/sources.list
And add the following line
deb http://backports.debian.org/debian-backports lenny-backports main

Get packages upgraded from backports.debian.org (Recommended!)
This setting is recommended Without this setting you don't get security updates
Replacing backports.debian.org/debian-backports with the mirror in question.
Normally packages won't get upgraded automatically from backports.debian.org (due to the NotAutomatic flag). To get packages that you have installed from backports automatically updated you have to have add a pinning, either to /etc/apt/preferences:
Package: *
Pin: release a=lenny-backports
Pin-Priority: 200

Replacing backports.debian.org/debian-backports with the mirror in question.
# apt-get update
# apt-get upgrade
# apt-get -t lenny-backports install git

Now git version should be "git version 1.7.1"

# git --version
git version 1.7.1

if not please check
$ /usr/bin/git --version
$ /usr/local/bin/git --version
HACK: Then copy the new version on the old one [B]
# sudo cp /usr/bin/git /usr/local/bin/git
[A] For more info about Debian backports see http://backports.debian.org/Instructions/
[B] if you have a better idea please email me


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值