国内镜像下载代码的痛点“慢”
repo速度太慢
需要排队:
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-16.0.0_r4
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
remote: Waiting in queue... (Position: 6)
经常repo init半天不动,大家以为repo卡死了,要等待好几个小时才可以完成。
好不容易repo init好了后,发现repo sync又是很慢。
repo sync
Syncing: 0% (4/1011) 49:00 | 4 jobs | 13:03 platform/boSyncing:
有学员反应花了几天才repo成功,这个情况也确实可能有的,但是最后时间虽然长,也是可以repo sync下来的。
文章参考:
清华镜像(确实比较慢)
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
中科大镜像 (稍微好一点)
https://mirrors.ustc.edu.cn/help/aosp.html
慢原因是啥?
1、repo的人越来越多,说明大家对aosp源码修改学习需求变大
2、清华大学镜像等开源节流,服务器肯定进行了降级
有没有快一些的方式呢?
解决办法
使用代理方式
这个有的有条件可以访问google外网,可以直接访问google官方库
下载repo
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
再进行初始化仓库
repo init --partial-clone -b main -u https://android.googlesource.com/platform/manifest
进行repo
$ repo sync -c -j8
参考网站:https://source.android.com/docs/setup/download?hl=zh-cn
国内镜像直接使用压缩包方式
参考:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
压缩包的下载
wget -c https://mirrors.ustc.edu.cn/aosp-monthly/aosp-latest.tar
速度在40m以上

注意下载完成记得确认一下md5是否正确
https://mirrors.ustc.edu.cn/aosp-monthly/
主要目的以防网络下载偶尔有错误,要保证压缩包数据完全正常.
使用如下命令md5sum进行计算压缩包md5码
test@test:~/disk_2T/ustc-aosp16$ md5sum aosp-latest.tar
229f0c7d457d777417a5e768ce339892 aosp-latest.tar
发先和官网匹配,说明压缩包没有问题

解压压缩包
tar xf aosp-latest.tar
cd AOSP
git -C ./.repo/manifests.git/ remote set-url origin https://mirrors.ustc.edu.cn/aosp/platform/manifest.git
注意可能等待时间较长,这个也需要耐心和硬盘速度有关系,大概20分钟。
切换成目标branch然后进行repo sync
需要到解压的aosp目录中去,然后
cd .repo/manifests
然后进行checkout到自己目标的branch既可以,我这里是android-16.0.0_r4
test@test:~/disk_2T/ustc-aosp16/aosp/.repo/manifests$ git checkout -b android-16.0.0_r4 remotes/origin/android-16.0.0_r4
Branch 'android-16.0.0_r4' set up to track remote branch 'android-16.0.0_r4' from 'origin'.
Switched to a new branch 'android-16.0.0_r4'
核心命令就是:
git checkout -b android-16.0.0_r4 remotes/origin/android-16.0.0_r4
注意这类的remotes/origin/android-16.0.0_r4可以通过git branch -a进行获取。
最后进行repo sync命令执行
repo sync -j 4
Syncing: 100% (1011/1011), done in 56m38.096s
Finalizing sync state...
Checking for bloat: 100% (98/98), done in 13.327s
warning: Project "platform/prebuilts/clang/host/linux-x86" is accumulating unoptimized data. Please run "repo sync --auto-gc" or "repo gc --repack" to clean up.
repo sync has finished successfully.
注意这个时间也可能较长,我这也花了5个小时,大家不要着急,可以晚上repo第二天早上看。
其他方案尝试:
有同学反应建议可以使用其他学校镜像进行下载,比如南京大学,但是尝试后发现repo sync都有比较多的错误,最后没有成功。学员朋友提供了其他学校的我这边也没有挨个尝试了,大家感兴趣的可以去试试。

原文地址及framework手把手指导:
https://mp.weixin.qq.com/s/oLlJMDEKYqcjoPThzzdaqA

338

被折叠的 条评论
为什么被折叠?



