国内下载android源码
因为google在国内是被墙掉的,所以使用官方版下载是很难下载成功。不过还好,我们可以通过国内的镜像下载(科大源或清华源)。
方法一
参考Google官方教程或《同步android源码(官方版)》,将里面的url: https://android.googlesource.com/ 全部使用 https://aosp.tuna.tsinghua.edu.cn/ 或 git://mirrors.ustc.edu.cn/aosp/ 代替即可。
方法二
修改本地的.gitconfig文件,在这个文件里面改变url指向。然后其他命令操作不变,继续执行。
[url "https://aosp.tuna.tsinghua.edu.cn/"]
insteadOf = https://android.googlesource.com/
或
[url "git://mirrors.ustc.edu.cn/aosp/"]
insteadOf = https://android.googlesource.com/
方法三
使用每月更新的初始化包
由于首次同步需要下载 24GB 数据,过程中任何网络故障都可能造成同步失败,我们强烈建议您使用初始化包进行初始化。
下载 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar, 或 http://mirrors.ustc.edu.cn/aosp-monthly/aosp-latest.tar 下载完成后记得根据 checksum.txt 的内容校验一下。
由于所有代码都是从隐藏的 .repo 目录中 checkout 出来的,所以我们只保留了 .repo 目录,下载后解压 再 repo sync 一遍即可得到完整的目录。
使用方法如下:
wget https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
或wget http://mirrors.ustc.edu.cn/aosp-monthly/aosp-latest.tar
tar xf aosp-latest.tar
cd AOSP # 解压得到的 AOSP 工程目录
# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
repo sync # 正常同步一遍即可得到完整目录
# 或 repo sync -l 仅checkout代码
此后,每次只需运行 repo sync 即可保持同步。 我们强烈建议您保持每天同步,并尽量选择凌晨等低峰时间