由于国内访问外网的限制,无法直接访问Google网站进行Android源码的下载。这里提供了一种利用国内镜像源下载的方法仅供参考。
目前,可用的镜像源一般是科大和清华的,具体使用差不多。
科大源:https://lug.ustc.edu.cn/wiki/mirrors/help/aosp
清华源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
这里我选择科大的镜像进行说明。
1.安装ubuntu系统,或者虚拟机。
2.安装java的sdk
3.安装依赖包 ,命令是:sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
4.安装调试工具,命令是:sudo apt-get install valgrind
5.安装git工具:sudo apt-get install git
配置git环境
git config –global user.email “[email protected]”
git config –global user.name “test”
其中[email protected]为你自己的邮箱,也可以随便写。
命令如下:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
如果以上命令无法下载,可以尝试修改为
curl https://storage-googleapis.lug.ustc.edu.cn/git-repo-downloads/repo > ~/bin/repo
替代原来的链接。
新建一个文件夹用来放置下载的源码。我这里选择再home目录下,命名为android-9.0,可随自己喜好命名。
mkdir android-9.0
cd android-9.0
将上面新建的android-9.0文件夹作为仓库用来存储代码,现在我们来对它进行初始化。通过执行初始化仓库命令可以获取AOSP项目master上最新的代码,命令如下:
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
如果要下载某一个指定版本的代码,可以在后面加指定参数。如下载Android-9.0代码,使用如下命令:
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-9.0.0_r1
具体的版本列表可以到其镜像网站下查看:http://mirrors.ustc.edu.cn/aosp/platform/manifest.git/refs/heads
如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的:
REPO_URL = 'https://gerrit-googlesource.lug.ustc.edu.cn/git-repo'
执行以下命令:
repo sync
下面开始漫长的等待,等待其下载源码完成即可。
如果中途有事或者断网等其他原因导致下载中断,下次重新运行以上命令即可,会自动根据之前的进度进行同步。
如果发现卡在某一步骤很久都没更新,也可以先手动中断后再重新执行以上命令进行同步。
附一张我执行repo sync之后的截图,仅供参考。