Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發實例

在企業內網架一台 Android 原始碼鏡像伺服器

編輯:Android 開發實例

為什麼要自建鏡像

當團隊有多台機器在同一個伺服器上開發,每次都從網際網路抓 Android 原始碼既慢又浪費頻寬。把 OMAP-Android 的程式庫在本機做一份鏡像,成員就能在內網快速 clone,不必再繞外網。

前置條件

本文假設本機伺服器已經裝好 repo、git 與一台 git server。若尚未準備,請參考:

  • 安裝 Repo:https://source.android.com/download
  • 安裝 Git 與架設 Git Server:OMAP wiki 的 Git 章節

重要:如果你在防火牆後面工作,建立鏡像時必須用到 corkscrew。設定 corkscrew 時有個關鍵細節——要讓 git 僅在 clone kernel.org 與 omapzoom.org 時才經過 corkscrew。否則當你之後要從本機鏡像做 clone,git 也會硬走防火牆,結果找不到你的內網伺服器。

建立鏡像

在本機伺服器上開一個目錄放鏡像。請注意 git server 必須設定為要對外匯出這個目錄。舉例來說,若 git server 匯出的是 /pub/gittrees,那麼可以這樣建:

mkdir /pub/gittrees/omap-android/

接著執行:

cd /pub/gittrees/omap-android/
repo init -u git://git.omapzoom.org/repo/android/platform/omapmanifest.git --mirror
repo sync

修改 manifest 指向內網

sync 完成後還有一步不能省:要改 OMAP-Android 的 manifest,讓成員 clone 時被導向本機伺服器而不是外部站台。做法是先 clone 一份 manifest 下來(以一般 user 身分即可,只要在鏡像所在目錄有寫入權限)。以下範例假設本機 IP 是 192.168.0.100,且 git server 以 --base-path=/pub/gittrees 啟動:

cd ~
git clone git://192.168.0.100/omap-android/repo/android/platform/omapmanifest.git

編輯 ~/omap-android-manifest.git/default.xml,把遠端 korg 與 omap 的 fetch 位置改成鏡像的 IP 與目錄名稱,例如:

+      fetch="git://192.168.0.100/omap-android/" />

最後把這個改動 commit 並推回上層 git 樹(下方 user 為修改 manifest 的使用者名稱):

cd ~/omap-android-manifest.git
git commit -a
git push [email protected]:[email protected]

鏡像設定至此完成。

從鏡像 clone

同一個網路上的開發機只要執行以下指令即可:

cd ~
mkdir mydroid
cd mydroid
repo init -u git://192.168.0.100/omap-android/repo/android/platform/omapmanifest.git
repo sync

一個容易忘的維護陷阱

重要:之後若用 repo sync 更新鏡像,而 manifest 期間被上游改動過,這次 sync 會把你先前對 default.xml 做的修改覆蓋掉。所以每次更新鏡像前,先確認 manifest 是否有變動。

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