Windows 環(huán)境下載 Android 源碼

轉(zhuǎn)載自https://blog.csdn.net/freekiteyu/article/details/70939672

Windows 環(huán)境下載 Android 源碼

前言

Android 官網(wǎng)(該方式不適合 Windows 平臺(tái)):https://source.android.com/source/downloading.html

可是我就想在 Windows 中使用 Source Insight 看看源代碼,當(dāng)然可以!

準(zhǔn)備環(huán)境

1、安裝 git
2、安裝 Python
3、自備梯子
4、硬盤剩余容量最好大于 100G

1#. 安裝 git

官網(wǎng):https://git-scm.com/downloads/

圖形化工具:https://tortoisegit.org/

2. 安裝 Python

官網(wǎng):https://www.python.org/downloads/

安裝參考:http://jingyan.baidu.com/article/c910274be14d64cd361d2dd8.html

只需要安裝好運(yùn)行環(huán)境即可

3. 自備梯子

沒有梯子?那就使用清華源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

下載源碼

1. 打開 Git Bash,用 git 克隆源代碼倉(cāng)庫(kù)

git clone https://android.googlesource.com/platform/manifest.git
//沒有梯子使用清華源
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
這里寫圖片描述

這時(shí) D:/android_source_code/ 目錄下會(huì)出現(xiàn)一個(gè) manifest 目錄,進(jìn)入此目錄,里面除了 git 的配置目錄外,clone 下來了一個(gè) default.xml 文件。

2. 切換到想要的源碼版本分支

去這里 https://source.android.com/source/build-numbers.html#source-code-tags-and-builds

找到想要的版本分支,并復(fù)制。

cd manifest
//沒有梯子,使用 git branch -a 查看所有分支,找到想要的分支
git branch -a
git checkout android-6.0.1_r79 //這里以 6.0 最后一個(gè)版本下載
image.png
image.png
image.png

3. 使用 Python 執(zhí)行腳本進(jìn)行源代碼下載

將下面的代碼復(fù)制,創(chuàng)建文件 python_download.py,并保存。

import xml.dom.minidom
import os
from subprocess import call
 
# 1. 修改為源碼要保存的路徑
rootdir = "D:/android_source_code/Android_6_0_1"
 
# 2. 設(shè)置 git 安裝的路徑
git = "C:/Develop/Git/bin/git.exe"

# 3. 修改為第一步中 manifest 中 default.xml 保存的路徑
dom = xml.dom.minidom.parse("D:/android_source_code/manifest/default.xml")
root = dom.documentElement
 
#prefix = git + " clone https://android.googlesource.com/"
# 4. 沒有梯子使用清華源下載
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)

4. 執(zhí)行 Python 腳本開始下載

打開 Python 客戶端

這里寫圖片描述

打開上一步保存的 python_download.py 腳本文件

這里寫圖片描述

點(diǎn)擊 Run->Run Module 來運(yùn)行腳本,或直接按F5運(yùn)行。


image.png

靜靜地等待下載完成吧。

ps:建議下載先去掉default.xml文件中其他的代碼,先拿一個(gè)文件夾下載試,例framework/base

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容