Android源码(window下如何获取)

    xiaoxiao2021-03-25  75

    概要

    Android源码由Git进行管理,由于源码由众多的模块组成,每个模块又可能依赖许多第三方库,所以如果想要通过git链接一个个clone下来的话工作量将会非常大,所以Google用Python编写了一个repo工具用来批量下载Android源码(但是这个工具需要linux环境,如果想在windows下使用我们就必须在windows环境下搭建一个模拟的linux环境,这个模拟的linux环境我们可以用Cygwin来搭建)。 首先Google用一个Git仓库用来记录当前Android版本下各个子项目的Git仓库分别处于哪一个分支,这个仓库通常叫做:manifest仓库。这个仓库里面有一个XML文件,其实就是一个文件清单,列出了本代码仓库依赖哪些代码,该去哪下载,分支是什么。repo工具首先会clone这个仓库,然后根据这个XML文件(default.xml)列出的路径去批量下载源码。在windows下一般可以用以下两种方法来下载Android源码。

    注意:由于google的链接被墙了,所以我们可以使用清华大学提供的镜像链接进行下载 https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

    通过Python批量下载

    需要工具如下:

    下载git,安装 官方下载:https://git-scm.com/downloads/, 下载python,安装 官方网址:http://www.python.org


    打开Git Bash,执行命令,我是放在E盘的,路径可自定义 git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git输入命令,切换到manifest目录 cd manifestGit tag 列出android各个分支版本 下载android-7.0系统源码,输入下面命令,如果要下载其他版本源码,checkout git tag列出的版本号即可git checkout android-7.0.0_r6 checkout之后,manifest/default.xml文件中记录的就是android7.0系统各个模块的路径, 下面就轮到python出场了,这里用的是网上的一段python代码,实现源码的批量下载 执行此脚本的前提是已经执行了git checkout,选择好了要下载的Android源码版本,如果你的manifest文件不是C:\Android\Android Src\manifest\default.xml,

    还要把里面的git.exe的路经修改成你的安装路径,请自行修改脚本。 download-src.py源码:

    import xml.dom.minidom import os from subprocess import call #downloaded source path rootdir = "E:/Android/AndroidSource" #git program path git = "D:/Program Files/git/Git/bin/git.exe" dom = xml.dom.minidom.parse("E:/Android/AndroidSource/default.xml") root = dom.documentElement 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)

    执行这个脚本之后将会自动下载源码


    国内镜像速度还是很快的。一会就下载了这么多文件。

    转载请注明原文地址: https://ju.6miu.com/read-33548.html

    最新回复(0)