星期三, 5月 25, 2011

下載 Android source 出現 timed out 的解決方法

下載 android source 的方法在官網:

http://source.android.com/source/downloading.html

如果你公司網路只開放 80 port, 那你很有可能會看到下列錯誤訊息:

bash$ repo init -u git://android.git.kernel.org/platform/manifest -b donut
gpg: keyring `~/.repoconfig/gnupg/secring.gpg' created
gpg: keyring `~/.repoconfig/gnupg/pubring.gpg' created
gpg: ~/.repoconfig/gnupg/trustdb.gpg: trustdb created
gpg: key 920F5C65: public key "Repo Maintainer " imported
gpg: Total number processed: 1
gpg: imported: 1

Getting repo ...
from git://android.git.kernel.org/tools/repo.git
android.git.kernel.org[0: 199.6.1.173]: errno=Connection timed out
android.git.kernel.org[0: 130.239.17.13]: errno=Connection timed out
android.git.kernel.org[0: 149.20.4.77]: errno=Connection timed out
android.git.kernel.org[0: 149.20.20.141]: errno=Connection timed out
fatal: unable to connect a socket (Connection timed out)
bash$

這問題的產生原因, 可能是因為 git 的 9418 port 被封, 參考 git 的技術手冊, 可以知道目前 git 有 local, git, http(s), ssh 共 4 種 protocol 可以使用, 因此我們可以用 http 來取代 git, 只要做點小修改就可以了.

1. 修改 repo 這個檔案 REPO_URL= 把 git:// 改成 http://
如下:


bash$ sed -i -e "s/REPO_URL='git:/REPO_URL='http:/" ~/bin/repo

2. 在命令列中把 git:// 改成 http:// 如:

bash$ repo init -u http://android.git.kernel.org/platform/manifest.git

正常來說, 接下來的 repo sync 還是會 timed out, 這是因為 repo sync 會引用 .repo 目錄裡的 manifest.xml, 所以最後我們只要修改 manifest.xml 就好了, 這個檔案在 repo init 之後才會出現, 如果你找不到, 要先做 repo init.

3. 修改 .repo/manifest.xml 把 fetch= 從 git:// 改成 http://

bash$ sed -i -e 's/fetch="git:/fetch="http:/' .repo/manifest.xml

沒有留言: