Window系统下载安卓源码

2022-01-06  本文已影响0人  愿你我皆是黑马
由于自己电脑是Mac的,最近工作的电脑是window的。就想着找一下window的源码下载方式(从步骤流程来看,这方式应该是跨系统的,但只在window下进行过验证),稍微记录一下。

准备200g空闲容量

#下载源码(使用清华源)
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git #这时目录下会出现 manifest 目录,此目录有一个default.xml文件。
#切换到想要的源码版本分支
git branch -a
git switch -c 分支名
#修改下面提供的python脚本,并使用python运行
python download.py

新建 download.py文件内容如下:

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

rootdir = "修改为源码要保存的路径(目录路径),最好不要在.git目录里。建议和manifest目录同级"
 
git = "修改为git安装的路径,如果git设置了环境变量这里的值直接写git就行"

dom = xml.dom.minidom.parse("修改为第一步中manifest中default.xml保存的路径(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)

要下挺久的...,做好心理准备。


如果你只是想看看framework源码,不需要下载这个了。下载设置好源,使用android studio点到想看的类,就可以了。

上一篇 下一篇

猜你喜欢

热点阅读