Timeliness note: The mirror URLs in this article were valid for a specific period. Both TUNA (Tsinghua) and USTC (Hefei) AOSP mirror addresses have changed multiple times. Always consult each mirror’s official help page for current URLs.

AOSP source is enormous (~70GB), making downloads from Google’s official servers via VPN painfully slow. Chinese mirrors offer much faster speeds.

Replacing the Remote URL

Replace https://android.googlesource.com/ with the TUNA mirror:

1
git://aosp.tuna.tsinghua.edu.cn/android/

For an existing checkout, modify the aosp remote fetch URL in .repo/manifest.xml:

1
2
3
4
5
6
7
<manifest>
   <remote  name="aosp"
-           fetch="https://android.googlesource.com"
+           fetch="git://aosp.tuna.tsinghua.edu.cn/android/"
            review="android-review.googlesource.com" />

   <remote  name="github"

Download the repo Tool

1
2
3
4
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Initialize the Working Directory

1
2
3
4
5
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
## For a specific version (e.g. Android 5.1.1):
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-5.1.1_r3

If gerrit.googlesource.com is unreachable, edit ~/bin/repo and change the REPO_URL line:

1
REPO_URL = 'https://gerrit-googlesource.lug.ustc.edu.cn/git-repo'

Sync the Source Tree

1
repo sync

Run this command repeatedly to keep the source tree up to date.

Switching an Existing Repo to a Chinese Mirror

Edit .repo/manifests.git/config, change:

1
url = https://android.googlesource.com/platform/manifest

to:

1
url = git://mirrors.ustc.edu.cn/aosp/platform/manifest

This method also works for syncing CyanogenMod code from TUNA.


References