- 安装git
- 安装python,配置环境变量,后面用命令行比较方便
- 在git里获取对应default.xml,用来下载各个库
git clone https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest.git
下载需要的对应分支(默认AOSP_MASTER分支):
git checkout android-10.0.0_r36
之后就下载了default.xml
可以在build\core\build_id.mk看到build id,然后去https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds 找对应分支
- python代码,命令行执行python download.py等待下载
import xml.dom.minidom
import os
from subprocess import call
# 1.想要下载的源码目录
rootdir = "D:\opensdk\source_code"
# 2.git
git = "C:/Program Files/Git/bin/git.exe"
# 3.第3步里下载的xml路径
dom = xml.dom.minidom.parse("D:\opensdk\default.xml")
root = dom.documentElement
# 4.
prefix = git + " clone -b android-10.0.0_r36 https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/"
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)
PS: 这种方式下载的貌似不全,有些库会下载失败
参考连接
https://www.cnblogs.com/larack/p/10896875.html