??? 之前我是去Android官方網(wǎng)站下載最新Android代碼,但是這種方法需要FQ,而且有時(shí)候FQ又不太方便,今天我發(fā)現(xiàn)一個(gè)不錯(cuò)的網(wǎng)站,是清華大學(xué)搞的,跟Android官方的代碼基本保持同步,而且下載方法跟Android官方的也類似。下面是網(wǎng)站地址:
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
下面我簡單介紹一下幾種下載方法:
準(zhǔn)備工作
方法一
- 下載repo工具
1: mkdir ~/bin
2: PATH=~/bin:$PATH
3: curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
4: chmod a+x ~/bin/repo
- 建立工作目錄
1: mkdir WORKING_DIRECTORY
2: cd WORKING_DIRECTORY
- 初始化倉庫
1: repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
2: ## 如果提示無法連接到 gerrit.googlesource.com,可以編輯 ~/bin/repo,把 REPO_URL 一行替換成下面的:
3: REPO_URL = 'https://gerrit-google.tuna.tsinghua.edu.cn/git-repo'
- 同步源碼樹
1: repo sync
方法二 建立本地鏡像
重點(diǎn)說一下這種方法,這種方法首先在本地建立一個(gè)Andriod代碼的鏡像,第一次需要下載大量的代碼(我的占了120GB左右的空間),然后執(zhí)行類似方法一,不過這次的Android代碼源是在本地,所以速度很快。以后更新的時(shí)候,先更新本地Andriod代碼鏡像,再更新Android代碼。我用的就是這種方法,我的代碼鏡像是FQ的時(shí)候從Android官方下載的,所以每次更新Android代碼鏡像的時(shí)候都需要FQ,不方便。
步驟:
- 下載
repo
工具和建立工作目錄 (參照方法一)
這里需要修改一下repo工具:
將
1: REPO_URL = 'https://gerrit.googlesource.com/git-repo'
修改為:
1: REPO_URL = 'https://gerrit-google.tuna.tsinghua.edu.cn/git-repo'
- 初始化
1: repo init -u https://aosp.tuna.tsinghua.edu.cn/mirror/manifest --mirror
- 同步源碼樹
1: repo sync
然后,就可以從本地sync代碼了:
1: repo init -u WORKING_DIR/mirror/platform/manifest.git
2: repo sync
下面是Android官方的說明:
Using a local mirror
When using several clients, especially in situations where bandwidth is scarce, it is better to create a local mirror of the entire server content, and to sync clients from that mirror (which requires no network access). The download for a full mirror is smaller than the download of two clients, while containing more information.
These instructions assume that the mirror is created in /usr/local/aosp/mirror. The first step is to create and sync the mirror itself. Notice the --mirror flag, which can be specified only when creating a new client:
$ mkdir -p /usr/local/aosp/mirror $ cd /usr/local/aosp/mirror $ repo init -u https://android.googlesource.com/mirror/manifest --mirror $ repo syncOnce the mirror is synced, new clients can be created from it. Note that it's important to specify an absolute path:
$ mkdir -p /usr/local/aosp/master $ cd /usr/local/aosp/master $ repo init -u /usr/local/aosp/mirror/platform/manifest.git $ repo syncFinally, to sync a client against the server, the mirror needs to be synced against the server, then the client against the mirror:
$ cd /usr/local/aosp/mirror $ repo sync $ cd /usr/local/aosp/master $ repo sync?It's possible to store the mirror on a LAN server and to access it over NFS, SSH or Git. It's also possible to store it on a removable drive and to pass that drive around between users or between machines.
更新本地Android鏡像
由于我最初的Android鏡像來自Android官方,需要FQ,所以需要作如下修改:
如果你之前已經(jīng)通過某種途徑獲得了 AOSP 的源碼(或者你只是 init 這一步完成后),你希望以后通過 TUNA 同步 AOSP 部分的代碼,只需要將 .repo/manifest.xml
把其中的 aosp 這個(gè) remote 的 fetch 從 https://android.googlesource.com
改為 https://aosp.tuna.tsinghua.edu.cn/
或 git://aosp.tuna.tsinghua.edu.cn/aosp
。
1: <manifest>
2:?
3: <remote name="aosp"
4: - fetch="https://android.googlesource.com"
5: + fetch="https://aosp.tuna.tsinghua.edu.cn" 或 "git://aosp.tuna.tsinghua.edu.cn/aosp"
6: review="android-review.googlesource.com" />
7:?
8: <remote name="github"
同時(shí),修改 .repo/manifests.git/config
,將
1: url = https://android.googlesource.com/platform/manifest
更改為
1: url = https://aosp.tuna.tsinghua.edu.cn/platform/manifest
2: # 或 url = git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest
?
完。
本文摘自 :https://blog.51cto.com/u