一、如何下載安卓系統源碼

 

Android 是一個適用於移動設備的開源操作系統以及由 Google 主導的相關開源項目。此網站和 Android 開源項目 (AOSP) 代碼庫可爲您提供所需信息和源代碼,供您創建定製的 Android 操作系統版本,將設備和配件移植到 Android 平臺,同時確保您的設備符合兼容性要求,從而讓 Android 生態系統維持良好穩健的運行環境,以便更好地服務於數百萬用戶。 

作爲一個開源項目,Android 的目標是避免出現任何集中瓶頸(即沒有任何行業參與者可一手限制或控制其他任何參與者的創新)。爲此,Android 被打造成了一個適用於消費類產品的完整高品質操作系統,並配有可定製源代碼,該代碼可移植到幾乎所有設備以及所有用戶均可使用的公開文檔中(英文網址:source.android.com;簡體中文網址:source.android.google.cn)。

在公開文檔中有關於源碼的下載方法: https://source.android.google.cn/setup/downloading

 

敲黑板內容:

              你可以按照公開文檔的下載方法下載源碼,但是環境需要在linux下,那麼windows如何下載呢,這裏提供兩種方案,中心思想是一樣的。

一、模擬Linux環境:

          1.下載 Cygwin安裝windows下的Linux模擬環境,用谷歌的Repo,repo 是一款工具。,然後就是一路的下一步(注意:如果第一次安裝,你需要選install from internet,然後就是選安裝位置,還有臨時文件的位置和連接網絡的設置,這些都默認就可以.關鍵的一步是選擇要安裝的庫和程序,以下這幾個是要安裝的:

Net -> curl

Devel -> git,git-completion,git-gui,gitk

Libs -> libreadline6,libiconv2

Editors -> vim

Python -> python

如果不好找,你可以在上面的Search上搜索.

2.下載Repo

啓動Cygwin,然後cd /bin,切到bin目錄執行

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

下載repo到bin目錄.然後執行

chmod a+x repo賦予它可執行的權限.

初始化倉庫:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

如果需要某個特定的 Android 版本:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1

同步源碼樹(以後只需執行這條命令來同步):

repo sync

 

二、自制腳本下載:

下載git,安裝 官方下載:https://git-scm.com/downloads/
下載python,安裝 官方網址:http://www.python.org
打開Git Bash,執行命令,我是放在c盤的,路徑可自定義
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
輸入命令,切換到manifest目錄
cd manifest
Git tag 列出android各個分支版本
下載android-cts-4.0_r1系統源碼,輸入下面命令,如果要下載其他版本源碼,checkout git tag列出的版本號即可
git checkout android-cts-4.0_r1
checkout之後,manifest/default.xml文件中記錄的就是android-cts-4.0_r1系統各個模塊的路徑,
下面就輪到python出場了,實現源碼的批量下載
執行此腳本的前提是已經執行了git checkout,選擇好了要下載的Android源碼版本,按照以下源碼請自行修改腳本。

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

#downloaded source path  
rootdir = "你的下載源碼路徑"  

#git program path  
git = "你的git路徑/git.exe"
dom = xml.dom.minidom.parse("你的defalut路徑/manifest/default.xml")  
root = dom.documentElement  

prefix = git + " clone https://aosp.tuna.tsinghua.edu.cn/"  
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)  


執行這個腳本之後將會自動下載源碼

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章