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

下載 Android 原始碼時的常見錯誤與解法

編輯:關於 Android 程式設計

環境:Ubuntu 11.04,目標版本 Android-4.1.1.1_r4。下載流程依官方文件(source.android.com/source/downloading.html)執行 repo init 加 repo sync 即可,但過程中幾乎一定會遇到中斷與報錯。

典型錯誤

fatal: Not a git repository: '/home/yourname/android_source/.repo/projects/abi/cpp.git'
error: Cannot fetch platform/abi/cpp
warn: --force-broken, continuing to sync
error: Cannot fetch platform/cts
error: The requested URL returned error: 403 while accessing
    https://android.googlesource.com/platform/development/info/refs
fatal: HTTP request failed
error: gnutls_handshake() failed: A TLS packet with unexpected length was received.

這類錯誤多半是某個子專案的 .git 狀態壞掉了,導致後續同步連鎖失敗。

解法一:刪掉壞掉的專案再重跑

rm -f -r cpp.git
rm -f -r cts.git
repo sync

把 .repo/projects 下對應的殘缺目錄刪除,讓 repo 重新抓取該專案,多數情況再跑一次 sync 就能順利完成。核心心法只有一個:保持耐心,反覆執行 repo sync,中斷的專案會被續傳補齊。

成功時會看到大量 Checking out files: 100% 與最後的 Syncing work tree: 100% (294/294), done.。

解法二:改用認證方式存取

另一種錯誤長這樣:

DownloadError: android.googlesource.com: <urlopen error [Errno 8]
    _ssl.c:503: EOF occurred in violation of protocol>
error: RPC failed; result=56, HTTP code = 200
fatal: early EOF
fatal: index-pack failed
error: Cannot fetch platform/external/qemu

官方的做法是改用帶認證的存取方式:

1. 瀏覽器登入 https://android.googlesource.com/new-password,以 Gmail 帳號登入;

2. 點擊「允許存取」,取得類似以下的資訊:

machine android.googlesource.com login git-<userName>.gmail.com password <password>
machine android-review.googlesource.com login git-<userName>.gmail.com password <password>

3. 把這段內容(換成你自己的帳號與密碼)附加到 ~/.netrc 檔案結尾;

4. 把下載 URI 改為 https://android.googlesource.com/a/platform/manifest(中間多一段 /a)。

官方解釋,由於存取基本上是匿名的,為了避免單一 IP 連線過多,服務端對同一 IP 的連線數做了限制;改用帳號認證即可放寬。因此在公司網路或虛擬機器中下載時,特別容易碰到這類截斷問題。

作者:iamcxl369

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