1.安装 git
官网:https://git-scm.com/downloads/
2.安装 Python
官网:https://www.python.org/downloads/
3.下载源码
1.下载manifest.git
方法一:git clone https://android.googlesource.com/platform/manifest.git(需要梯子)
方法二:git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git(清华源,不需要梯子)
2.checkout分支
git checkout 分支号 (分支号:切换到刚下载的manifest目录下,git bash使用git branch -a显示所有分支)
切换成功后会显示:You are in 'detached HEAD' state. You can look around, make experimental......
3.使用 Python 执行脚本进行源代码下载
1.创建文件 python_download.py,将下面代码复制进去 ,记得修改代码中路径
import xml.dom.minidom
import os
from subprocess import call
# 1. 修改为源码要保存的路径
rootdir = "G:/android_source"
# 2. 设置 git 安装的路径
git = "C:/Program Files (x86)/Git/bin/git.exe"
# 3. 修改为第一步中 manifest 中 default.xml 保存的路径
dom = xml.dom.minidom.parse("G:/android_source/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)