想在 Windows 中使用 Source Insight 看源代码,可按下面步骤操作:
准备环境(硬盘空间至少100G以上)
安装 git
安装 Python
自备梯子
- 安装 git
- 安装 Python (安装完后使用cmd一定要检测检测环境变量是否配置、是否安装成功,环境变量一般是自动配置的)
安装参考:jingyan.baidu.com/article/c91…
- 自备梯子
没有梯子?那就使用清华源:mirrors.tuna.tsinghua.edu.cn/help/AOSP/ 下载源码
- 打开 Git Bash,用 git 克隆源代码仓库
git clone android.googlesource.com/platform/ma…
//没有梯子使用清华源 (直接使用清华的镜像吧) git clone aosp.tuna.tsinghua.edu.cn/platform/ma…
这时运行后的 目录下会出现一个 manifest 目录,进入此目录,里面除了 git 的配置目录外,clone 下来了一个 default.xml 文件和还有两个文件
- 切换到想要的源码版本分支
去这里(没梯子进不去的) source.android.com/source/buil…
找到想要的版本分支,并复制(进不去往下看版本分支,通过命令进去)。
//切换到manifest目录
cd manifest
//没有梯子,使用 git branch -a 查看所有分支,找到想要的分支
git branch -a
git checkout --tranck android-12.0.0_r3 //这里以 12.0.0_r3 版本下载
- 使用 Python 执行脚本进行源代码下载
将下面的代码复制,创建文件 python_download.py,并保存。
import xml.dom.minidom
import os
from subprocess import call
1. 修改为源码要保存的路径
rootdir = "D:/android_source_code/Android_6_0_1"
2. 设置 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)
- 执行 Python 脚本开始下载 (在manifest 目录下只有.git和default.xml两个文件夹)后在打开cmd命令,先检测pytnon是否安装然后cmd进入文件 python_download.py所在位置,运行.py文件)
你就静静的等待下载,一天、两天很漫长不用管他了让他自己下就ok了