我在寻找下载android平台源码时发现了几种方法,有的方法已经失效,现在把测试成功的下载方法写下来:
1,环境要求
需要在linux环境下下载。我选用的是ubuntu
我在安装完ubuntu时报错“ubuntu is running in low-graphic mode”,解决方法如下:
选择第四项:exit to consle login
然后用用户名,密码登陆进去
执行命令
sudo apt-get update
sudo apt-get upgrade
执行后重启
2,下载git程序
git是一种版本控制软件。在终端中输入:
sudo apt-get install git-core gnupg flex bison gperf build-essential \zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev \libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown \libxml2-utils
3,设置下载目录
$ 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
4,开始下载内核源码
$ repo init -u https://android.googlesource.com/platform/manifest
如果要下载分支版本,使用以下格式的命令
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1.2
(查询android版本信息,参考 https://android.googlesource.com/platform/manifest/+refs)
最后,用以下命令checkout出源码到我们设置的工作目录:
$ repo sync
5,可能碰到的错误
1)error: RPC failed; result=56, HTTP code = XX MiB | XX KiB/s
碰到以上问题,一般是git没有正确安装,请使用第二步重新安装
2)
error: Failed connect to android.googlesource.com:443;Connection refused while accessinghttps://android.googlesource.com/a/platform/frameworks/base/info/refs
fatal: HTTP request failed
error: Cannot fetch platform/tools/motodev
error: Cannot fetch platform/frameworks/base
error: Cannot fetch platform/prebuilts/sdk
error: Exited sync due to fetch errors
解决方法:编辑/etc/hosts文件
$ vim /etc/hosts
增加下面内容,保存(提前保存好):
74.125.31.82 www.googlesource.com
74.125.31.82 android.googlesource.com
203.208.46.172 cache.pack.google.com
59.24.3.173cache.pack.google.com
如果出现无法保存的情况(一般是因为hosts为只读),用以下命令编辑:
$sudo gedit /etc/hosts
编辑保存hosts文件后重新输入:
$ repo sync