我们使用清华的镜像来下载Android源码, 将 https://android.googlesource.com/ 全部使用 https://aosp.tuna.tsinghua.edu.cn/ 代替即可。其说明在https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/,可以查看。先下载repo文件,它是一个脚本:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
这里在用户目录下新建设一个bin文件夹,将其添加到当前shell的环境变量中,然后创建repo文件,并让更改其权限为可执行。
下载完后repo,将其URL替换掉,因为为的镜像:
if not REPO_URL:
REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
REPO_REV = 'stable'
可以在http://androidxref.com上查看分支,创建下载目录和要下载的分支:
mkdir android-5.0.0_r2
cd android-5.0.0_r2
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-5.0.0_r2
此时会生成一个.repo文件夹。然后执行命令:
repo sync
便可同步代码。