由于国内网络原因,下载AOSP代码比较困难,只能通过国内的镜像文件来下载。
这里优先参考清华大学提供的镜像:AOSP | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
1.repo工具下载
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
或者使用tuna镜像里的repogit-repo | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror。
cd bin/
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
为了方便可以将其拷贝到你的PATH
里。
更新
repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新,可以将如下内容复制到你的~/.bashrc
里
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
并重启终端模拟器。
实测结果:
注:这里实测的是tuna的镜像repo。
本地电脑添加的环境变量如下:
export REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
export ANDROID_HOME=${HOME}/Android/Sdk
PATH="$HOME/bin:$HOME/.local/bin:$HOME/.bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
repo放置在了~/bin目录下。
2.依赖的工具安装(测试环境: deepinOS 20)。
git安装。
sudo apt-get install git
git config --global user.name userName
git config --global user.email "userName@qq.com"
# 这里安装的是:git version 2.20.1
deepinOS默认安装的python是2.7, 我们python依赖较新的python3。
python3安装。
sudo apt-get install python3
#默认python命令指向了python2.7,我们需要将python命令指向python3.7
sudo ln -sf /usr/bin/python3 /usr/bin/python
# 这里安装的python3版本如下:
#Python 3.7.3 (default, Apr 2 2021, 05:20:44)
#[GCC 8.3.0] on linux
#Type "help", "copyright", "credits" or "license" for more information.
3..repo镜像索引文件初始化包
正常情况下是使用repo init命令来同步.repo文件夹,但是由于网络稳定性和初始化大小原因,这里建议直接下载压缩包离线版本。
官网给到的方案如下:
使用每月更新初始化包
由于首次同步需要下载约 60GB 数据,过程中任何网络故障都可能造成同步失败,我们强烈建议您使用初始化包进行初始化。
下载 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar,下载完成后记得根据 checksum.txt 的内容校验一下。
由于所有代码都是从隐藏的 .repo
目录中 checkout 出来的,所以我们只保留了 .repo
目录,下载后解压 再 repo sync
一遍即可得到完整的目录。
使用方法如下:
curl -OC - https://mirrors.tuna.tsinghua.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
即可保持同步。 我们强烈建议您保持每天同步,并尽量选择凌晨等低峰时间
实测结果:
本地实测可行可靠的方案是直接从https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/站点选择需要的文件。
注意:这里建议使用迅雷下载,如果是浏览器直接下载会很慢而且很容易因为网络稳定性而中断下载,因为迅雷有加速。
比如这里选择了: https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
由截图可知浏览器直接直接下载需要1+天,有接近70GB的大小,单靠浏览器下载是很困难的。
4.解包和同步代码
下载完成后,直接解压即可,解压完成后,只有一个.repo的隐藏文件夹,即和repo init -u命令执行完后一样。
.repo
进入.repo所在目录,执行repo sync命令来同步所需的仓库代码,也可以同步个别所需的子仓库。例如:/system/nfc
cat .repo/manifest.xml
#<?xml version="1.0" encoding="UTF-8"?>
#<!--
#DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
#If you want to use a different manifest, use `repo init -m <file>` instead.
#
#If you want to customize your checkout by overriding manifest settings, use
#the local_manifests/ directory instead.
#
#For more information on repo manifests, check out:
#https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
#-->
#<manifest>
# <include name="default.xml" />
#</manifest>
cat .repo/manifests/default.xml | grep system/nfc
# <project path="system/nfc" name="platform/system/nfc" groups="pdk" />
repo sync system/nfc
如此,代码同步完毕。