新版本的android源碼要求git版本不得低於1.7.2,而ubuntu預設的不夠,或者用別的方式無法正常升級時,可採用下面這個方式來升級個git
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
1、安裝curl
在終端中執行 sudo apt-get install curl
2、建立一個~/bin目錄,並添加到環境變數中
$ mkdir ~/bin
$ PATH=~/bin:$PATH
3、下載repo指令碼並修改許可權為可執行
$ curlhttps://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x~/bin/repo
4、建立一個儲存android源碼的目錄,修改為最大許可權(這個是我自己增加的一個操作,怕以後操作許可權不足等麻煩),並進入到該目錄下
$ mkdir /opt/android_source
$ sudo chmod –R 777 /opt/android_source
$ cd /opt/android_source
5、初始化repo,並選擇要下載的分支(版本)
$ repo init -u https://android.googlesource.com/platform/manifest
$ repo init -u https://android.googlesource.com/platform/manifest-b
android-4.2_r1
備忘:在這過程中需要輸入你的姓名、郵箱等資訊。感覺只要輸入就可以了,我輸入了一個隨意名稱,我自己的126郵箱
6、開始下載源碼
$ repo sync
代碼下載過程中,經常提示以下錯誤:
error: Failed connect to android.googlesource.com:443;Connection refused while accessinghttps://android.googlesource.com/a/platform/frameworks/base/info/refs
fatal: HTTP request failed
error: Cannot fetch platform/tools/motodev
error: Cannot fetch platform/frameworks/base
error: Cannot fetch platform/prebuilts/sdk
error: Exited sync due to fetch errors
解決方案:編輯/etc/hosts檔案
$ vim /etc/hosts
增加下面內容,儲存(提前儲存好):
74.125.31.82 www.googlesource.com
74.125.31.82 android.googlesource.com
203.208.46.172 cache.pack.google.com
59.24.3.173cache.pack.google.com
然後重新輸入
$ repo sync