Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

動手抓取 Android L 原始碼:repo 工具完整流程

編輯:關於 Android 程式設計

Android L 發布後,想第一時間把原始碼拉下來研究,關鍵在於 repo 這個多倉庫管理工具。以下以 Linux(Ubuntu)環境為例,把整個流程走一遍。

一、取得 repo 腳本

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

curl 是 Linux 下以指令發送網路請求的常用工具,用它把 repo 抓下來後,將所在目錄加入 PATH 環境變數,之後就能直接呼叫。

二、用 repo 同步原始碼

抓取 master 分支:

(1) mkdir src && cd src
(2) repo init -u https://android.googlesource.com/platform/manifest
(3) repo sync

若想指定特定分支(以 5.0 為例):

(1) mkdir src && cd src
(2) repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r2
(3) repo sync

三、既有倉庫切換到新分支

先列出所有可用分支:

(1) cd .repo/manifests && git branch -a | cut -d / -f 3
android-4.4.4_r2.0.1
android-4.4_r1
android-4.4_r1.0.1
android-4.4_r1.1
android-4.4_r1.1.0.1
android-4.4_r1.2
android-4.4_r1.2.0.1
android-4.4w_r1
android-5.0.0_r1
android-5.0.0_r2

接著初始化、同步並全域切換:

(2) repo init -b android-5.0.0_r2
(3) repo sync
(4) repo start android-5.0.0_r2 --all
(5) repo branches
* android-5.0.0_r2 | in all projects
(6) cd external/jsmn && git branch
* android-5.0.0_r2

四、搭建區域鏡像倉庫

如果團隊內多人需要同一份原始碼,反覆從伺服器抓取既慢又耗流量,可以在內網架一台鏡像。

先從官方伺服器建立鏡像:

(1) mkdir -p ~/aosp/mirror
(2) cd ~/aosp/mirror
(3) repo init -u https://android.googlesource.com/mirror/manifest --mirror
(4) repo sync

其他人再從這台鏡像取用:

(1) mkdir -p ~/aosp/master
(2) cd ~/aosp/master
(3) repo init -u /home/username/aosp/mirror/platform/manifest.git
(4) repo sync

定期更新鏡像與本地倉庫:

(1) cd ~/aosp/mirror
(2) repo sync
(3) cd ~/aosp/master
(4) repo sync

整套流程走過一遍之後,後續每次更新只要重跑 repo sync 即可,日常使用相當省事。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved