1.安装git
作为一个android开发,这步应该可以跳过吧。
主要就是安装git,添加到环境变量
我个人是使用的Source Tree,毕竟我懒得记命令行
验证:cmd 输入git,出现git的命令提示(一大堆的东西),就知道是否安装成功了
2.安装Python
下载地址:https://www.python.org/downloads/
目前是3.7.4
记得安装完添加到环境变量(我选的默认安装,下面有添加到Path的选项)
验证:cmd 输入python,出现python的版本号,就知道是否安装成功了
3.下载mainfest
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
实际上就是个清单,标识源码的各个部分的git地址。
下载方法就是普通的git下载,这里就不多bb了,我用的图形化,点几下就行了
注意:默认下载的是master,需要切换到你需要的分支(我下载的是android-9.0.0_r9)
验证:目录下出现.git文件夹以及default.xml
4.根据mainfest下载源码
新建文件:python_download.py
输入以下内容,然后选择python_download.py文件,右键“Edit with IDLE”,点击编辑器上方菜单“Run”->"Run module"
import xml.dom.minidom
import os
from subprocess import call
# 1. 修改为源码要保存的路径
rootdir = "D:/AndroidSourceCode_9"
# 2. 设置 git 安装的路径
git = "C:/Program Files/Git/bin/git.exe"
# 3. 修改为第一步中 manifest 中 default.xml 保存的路径
dom = xml.dom.minidom.parse("D:/AndroidSourceCode/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)
然后就慢慢等吧。