下載msysgit,安裝
官方下載:http://code.google.com/p/msysgit/downloads/list,
打開Git Bash,執行命令
cd D:
git clone https://android.googlesource.com/platform/manifest.git
輸入命令,切換到manifest目錄
cd manifest
git tag 列出android各個分支版本
git tag
下載android-2.2系統源碼,輸入下面命令,如果要下載其他版本源碼,checkout git tag列出的版本號即可
git checkout android-2.2_r1
checkout之後,manifest/default.xml文件中記錄的就是android2.2系統各個模塊的路徑
我們來分析一下default.xml文件,
以bionic爲例,path屬性表示bionic源碼的相對路徑,假設android源碼在d:/android-source,下載bionic之後,應該存放在d:/android-source/bionic目錄
name屬性是bionic源代碼在庫上的路徑,完整的路徑就是:http://android.googlesource.com/platform/bionic.git,有了源碼下載路徑,執行git clone就可以將bionic源碼下載到本地
<project path="bionic" name="platform/bionic" />
Android源碼中project很多,一個一個下載比較麻煩,本人寫了一個python腳本,雙擊download-src.py執行此腳本,就可以將android完整源碼下載到本地。
PS:執行此腳本的前提是已經執行了git checkout,選擇好了要下載的Android源碼版本,如果你的manifest文件不是D:/manifest/default.xml,請自行修改腳本。
download-src.py源碼:
import xml.dom.minidom import os from subprocess import call #downloaded source path rootdir = "D:/android-source" #git program path git = "D:/Program Files/Git/bin/git.exe" dom = xml.dom.minidom.parse("D:/manifest/default.xml") root = dom.documentElement prefix = git + " clone https://android.googlesource.com/" suffix = ".git" if not os.path.exists(rootdir): os.mkdir(rootdir) for node in root.getElementsByTagName("project"): os.chdir(rootdir) d = node.getAttribute("path") last = d.rfind("/") if last != -1: d = rootdir + "/" + d[:last] if not os.path.exists(d): os.makedirs(d) os.chdir(d) cmd = prefix + node.getAttribute("name") + suffix call(cmd)