標籤:android style blog http color os io 檔案
下載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)