獲取Android源碼的簡明步驟

【0】準備環境:Linux or MacOS(也可以選擇虛擬機裡面安裝ubuntu,請註意若是要編譯Android源代碼,Windows暫不支持).
Note:The source download is approximately 6GB in size. You will need 25GB free to complete a single build, and up to 90GB (or more) for a full set of builds.

【1】安裝Git與curl:
$ sudo apt-get install git-core curl
【2】安裝Repo:一個使得Android與Git能夠簡單工作的工具。
• 確保在你的home目錄下有一個/bin的目錄(這個目錄其實也可以選擇其他位置), 並且把它添加到你的Path路徑下:
• $ mkdir ~/bin
• $ PATH=~/bin:$PATH
• 下載Repo腳本並確保它可執行:
• $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
【3】初始化Repo:
• 創建一個空的目錄來存放你的源文件.你可以像下面一樣創建一個目錄:
• $ mkdir WORKING_DIRECTORY
• $ cd WORKING_DIRECTORY
• 執行repo init的操作來獲取最新的源代碼列表。
• $ repo init -u https://android.googlesource.com/platform/manifest
然後使用 -b 來制定下載哪一個branch:(截至到目前,最新的版本是android-4.0.4_r1.2)
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.4_r1.2
• 期間有可能會提示你輸入賬戶名與郵箱,你可以輸入你的Google帳號(其實可以隨便填寫一個)。
【4】開始同步下載:
• 執行下面的命令既可(下載過程漫長)
$ repo sync
【5】可能遇到的問題:
如果你按上面的步驟執行後發現類似如下的錯誤:
[java]
1. Exception in thread Thread-3: 
2. Traceback (most recent call last): 
3.   File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner 
4.   self.run() 
5.   File "/usr/lib/python2.6/threading.py", line 484, in run 
6.   self.__target(*self.__args, **self.__kwargs) 
7.   File "/home/haili/android-4.0.4_r1.2/.repo/repo/subcmds/sync.py", line 200, in _FetchHelper 
8.   clone_bundle=not opt.no_clone_bundle) 
9.   File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 978, in Sync_NetworkHalf 
10.   and self._ApplyCloneBundle(initial=is_new, quiet=quiet): 
11.   File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1519, in _ApplyCloneBundle 
12.   exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet) 
13.   File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1583, in _FetchBundle 
14.   raise DownloadError('%s: %s ' % (req.get_host(), str(e))) 
15. DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out>   
16. … 
 
那麼解決方案如下:(學習自:/kf/201205/132492.html)
1.瀏覽器登錄https://android.googlesource.com/new-password,並用gmail帳號登錄;
2.點擊網頁上的“允許訪問”,得到類似:
[java]
1. machine android.googlesource.com login git-<userName>.gmail.com password <password> 
2. machine android-review.googlesource.com login git-<userName>.gmail.com password <password> 
 
3.把上面那段信息(<userName>和<password>用自己得到的真實信息)追加到~/.netrc文件(此文件位於HOME/用戶名/.netrc,若不存在可以新建這個文件)結尾;
4.下載地址的URI中添加字段a,如:https://android.googlesource.com/a/platform/manifest。
5.再執行上面的repo init與repo sync命令,即可開始下載。

 

摘自 四方城南

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *