我們使用清華的鏡像來下載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
便可同步代碼。