下載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.minidomimport osfrom subprocess import call#downloaded source pathrootdir = "D:/android-source"#git program pathgit = "D:/Program Files/Git/bin/git.exe"dom = xml.dom.minidom.parse("D:/manifest/default.xml")root = dom.documentElementprefix = 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)