文章目錄
導語
在國內由於網絡限制,下載Android源碼是一個非常麻煩的事情。當然,國內Android開發工程師辣麼多,下載還是有辦法,具體下載流程就下面開始記錄。
國內源碼資料
科大鏡像源:https://lug.ustc.edu.cn/wiki/mirrors/help/aosp
清華鏡像源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP
Android版本列表:http://mirrors.ustc.edu.cn/aosp/platform/manifest.git/refs/heads
在線查看源碼:http://androidxref.com
閱讀上面的資料,已經有下載相關教程。下面的內容是我下載代碼流程以及一些記錄。
一、環境準備
1. Linux環境
本文是在ubuntu16.04系統下才走
2. JDK環境
JDK下載地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html
3. 安裝GIT工具
sudo apt-get install git
git config –global user.email “[email protected]”
git config –global user.name “test”
其中[email protected]爲你自己的郵箱,也可以隨便寫。
4. 安裝依賴
sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
sudo apt-get install valgrind
二、安裝Repo工具
系統已經安裝了repo工具的可以跳過此步驟。
命令如下:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
如果以上命令無法下載,可以嘗試修改爲:
curl https://storage-googleapis.lug.ustc.edu.cn/git-repo-downloads/repo > ~/bin/repo
三、初始化倉庫
1、 創建文件夾
新建一個文件夾用來放置下載的源碼。目錄隨意,名字隨意。
mkdir aosp
cd aosp
2、 初始化Repo
將上面新建的aosp文件夾作爲倉庫用來存儲代碼,現在我們來對它進行初始化。通過執行初始化倉庫命令可以獲取AOSP項目master上最新的代碼,通過清華鏡像源爲例,命令如下:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
如果要下載某一個指定版本的代碼,可以在後面加指定參數。如下載Android-9.0代碼,使用如下命令:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest-b android-9.0.0_r1
四、同步代碼
執行以下命令:
repo sync -j8
-j8
是多線程下載,數字看電腦性能和服務器性能決定,也可以不帶。
接下來是漫長的等待過程。
五、同步失敗問題
下載失敗的概率非常非常大,反正我沒有一次可以一次完成下載的。如果下載遇到以下問題,可以參考一下。
1、沒有說明什麼直接報錯
error: Exited sync due to fetch errors
輸入: repo sync -f -j8 //加-f
2、網絡問題
error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated.
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
error: Cannot fetch platform/prebuilts/rust
warn: --force-broken, continuing to sync
Fetching projects: 100% (773/773)
error: Exited sync due to fetch errors
輸入: repo sync -j8