在Ubuntu 12.04上下載Android4.2源碼
下載過程分為以下幾個步驟
1、安裝curl
在終端中執行 sudo apt-get install curl
2、創建一個~/bin目錄,並添加到環境變量中
$ mkdir ~/bin
$ PATH=~/bin:$PATH
3、下載repo腳本並修改權限為可執行
$ curl https://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
正常情況下,上面就是下載android4.2源碼的流程,但我在下載的過程中遇到了下面問題
問題1:“A new repo command ( 1.18) is available.”
其實這個問題就是說你本地的repo版本不是1.18,比這個舊,在出現這個的時候,下面會有一個提示你怎麼操作的,如:
... A new repo command ( 1.18) is available.
... You should upgrade soon:
cp /home/pn/android/.repo/repo/repo/home/pn/bin/repo(執行這一句就可以),開始我苦悲的上網找這個的解決方法,,,,浪費不少時間。。
問題2:“error: Exited sync due to fetch errors...”
這個問題,網上都說是需要IP認證,其中我也根據
http://blog.csdn.net/fantao015/article/details/7625559
上面的操作,執行了一遍,其中包括注冊了一個@gmail.com郵件,後面發現我沒有用到這個也全部下載成功了。
問題3:經常提示
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.71.82 www.googlesource.com
74.125.71.82 android.googlesource.com
203.208.46.172 cache.pack.google.com
59.24.3.173cache.pack.google.com
然後重新輸入
$ repo sync
這個關於DNS解析,提示了訪問成功率,有興趣的童鞋可以研究下。。哎,如果早找到該操作,就節省了我不錯時間。
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11