Windows平台下載Android源碼(整理)


Google官方下載源碼使用的系統Ubuntu系統,不過現在我們需要在Windows系統中下載Android源碼文件。

網站的地址是:https://android.googlesource.com/

里面包括Android系統各個部分的源碼,我們只需要下載platform就行

點擊進入即可看到下載地址

地址是:https://android.googlesource.com/platform/manifest

 1.准備工作

Android的源代碼管理使用的是Git,所以安裝Git必不可少,Windows系統中使用的是mysysgit目前的版本是Git-1.9.5-preview20150319.exe,自行搜索下載。源代碼下載是使用Python腳本來完成的,所以還需要安裝一個python環境。

 

2.下載XML描述文件

進入一個文件夾,用來存儲XML描述文件,打開Git Bash執行如下命令

git clone https://android.googlesource.com/platform/manifest

 不出意外的話很快就會下載完成,如果出現中斷,請使用科學上網的方法重新下載,這里推薦一個亂燉hosts:http://levi.yii.so/archives/3553

下載完成后,執行如下命令:

git tag

 

選擇相需要下載的版本,然后執行如下命令,檢出相應的版本信息,這里已android-5.1.1_r8為例:

git checkout android-5.1.1_r8

 在default.xml文件中就定義了android源碼的路徑。

3.編寫python腳本下載源碼

文件內容如下,然后再進行具體解釋:

import xml.dom.minidom
import os
from subprocess import call

#downloaded source path
rootdir = "D:/Android/source/android-5.1.1_r8"

#git program path
git = "C:/Program Files (x86)/Git/bin/git.exe"

dom = xml.dom.minidom.parse("D:/Android/source/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)

第6行:rootdir 表示源碼的存儲路徑

第9行:git 表示git的安裝路徑

第11行:剛剛下載檢出的default.xml文件路徑

如果路徑有不同的地方,根據自己的境況修改

最后一步就是執行這個python腳本進行下載,,,等着吧。。。

python download-src.py

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM