安卓源碼AOSP下載清華大學鏡像過程及故障解決


參考: https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

目前下載安卓系統完整源碼只能使用repo工具, 且只能在Linux/Mac下執行. Windows下的理論上也可以下載, 但無法編譯, 參考: https://blog.csdn.net/freekiteyu/article/details/70939672

前提准備:

安裝好git和python, 准備磁盤空間100G+(如果是完整源碼大概是600G+, 安卓11單個分支需要110G空間), 時間一般至少需要3個小時+.

首先下載並安裝repo工具 (https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/)

安裝 Repo

Repo 是一款工具,可讓您在 Android 環境中更輕松地使用 Git。要詳細了解 Repo,請參閱開發部分。

要安裝 Repo,請執行以下操作:

  1. 確保主目錄下有一個 bin/ 目錄,並且該目錄包含在路徑中:

    mkdir ~/bin PATH=~/bin:$PATH
    
  2. 下載 Repo 工具,並確保它可執行:

    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
    chmod a+x ~/bin/repo
更新

repo的運行過程中會嘗試訪問官方的git源更新自己,如果想使用tuna的鏡像源進行更新,可以將如下內容復制到你的~/.bashrc里 (如果是最新的MacOS或者用的zsh請寫入 .zshrc里)

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

並重啟終端模擬器。

如果您需要完整的代碼(所有版本的), 請參考

使用每月更新的初始化包

由於首次同步需要下載約 95GB 數據,過程中任何網絡故障都可能造成同步失敗,我們強烈建議您使用初始化包進行初始化。

下載 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar,下載完成后記得根據 checksum.txt 的內容校驗一下。

由於所有代碼都是從隱藏的 .repo 目錄中 checkout 出來的,所以我們只保留了 .repo 目錄,下載后解壓 再 repo sync 一遍即可得到完整的目錄。

使用方法如下:

wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下載初始化包
tar xf aosp-latest.tar
cd AOSP   # 解壓得到的 AOSP 工程目錄
# 這時 ls 的話什么也看不到,因為只有一個隱藏的 .repo 目錄
repo sync # 正常同步一遍即可得到完整目錄
# 或 repo sync -l 僅checkout代碼

此后,每次只需運行 repo sync 即可保持同步。 我們強烈建議您保持每天同步,並盡量選擇凌晨等低峰時間

這里我們使用正常的步驟, 請先查閱 安卓源碼版本清單(轉載待查), 然后選擇一個分支, 例如android-11.0.0_r45

傳統初始化方法

建立工作目錄:

mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

初始化倉庫

repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest

如果提示無法連接到 gerrit.googlesource.com,請參照git-repo的幫助頁面的更新一節。

如果需要某個特定的 Android 版本(列表):(建議方案)

repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-11.0.0_r45

同步源碼樹(以后只需執行這條命令來同步), 此過程超級慢且任何錯誤都會中斷, 例如網絡故障或者磁盤空間不足:

repo sync
 

中間同步失敗了怎么辦?

由於前期磁盤不足, 最后雖然恢復了空間, 但是也導致repo sync的時候反復提示失敗:

error: Unable to fully sync the tree.
error: Checking out local projects failed.
Failing repos:
external/swiftshader
Try re-running with "-j1 --fail-fast" to exit at the first error.

Aborting
error: prebuilts/clang/host/darwin-x86/: platform/prebuilts/clang/host/darwin-x86 checkout 78c8a5102c5185a16a3589b6e31d083712bf99fb
error: Cannot checkout platform/prebuilts/clang/host/darwin-x86
Checking out: 100% (786/786), done in 29.824s

error: Unable to fully sync the tree.
error: Checking out local projects failed.
Failing repos:
hardware/libhardware
frameworks/ml
external/swiftshader
frameworks/av
prebuilts/remoteexecution-client
prebuilts/clang/host/darwin-x86

 

解決辦法:

刪除失敗的目錄, 然后重新調用 repo sync:

rm -r hardware/libhardware
rm -r  frameworks/ml
rm -r  frameworks/av
rm -r  prebuilts/remoteexecution-client prebuilts/clang/host/darwin-x86

強制更新單個項目, 可以用:

repo sync hardware/libhardware --force-sync


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM