0
点赞
收藏
分享

微信扫一扫

window环境下载Android系统源代码的方法

window环境下载Android系统源代码的方法

  1. 下载网址


网站的地址是:​​​https://android.googlesource.com/​​​ 里面包括Android系统各个部分的源码,我们只需要下载​​platform​​模块就行

地址:​​platform/manifestAndroid Platform Manifest​​

git地址:​​git clone https://android.googlesource.com/platform/manifest​

访问不了可以使用清华源:​​git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git​


  1. 准备环境


安装​​git​​​环境、安装​​python​​环境,这个自行百度下载安装


  1. 下载xml描述文件


安装git就会有Git Bash,打开git bash输入 ​​git clone https://android.googlesource.com/platform/manifest​​ 回车开始下载

下载完之后进入manifest目录,可以使用 ​​git tag​​​ 或者 ​​git branch -a​​ 查看所有的代码分支

选择需要下载的版本执行​​git checkout​​​命令,比如以android-11.0.0_r45为例:​​git checkout android-11.0.0_r45​

如果不想指定特别版本,只想同步最新的,可以使用​​git checkout master​​ 即可捡出最新的代码分支


  1. 编写python脚本​​download_android_platform_src.py​​自动下载
import  xml.dom.minidom
import os
from subprocess import call

#源代码存储路径
rootdir = "G:/android-11.0.0_r45"

#git安装路径
git = "C:/Program Files/Git/bin/git.exe"

dom = xml.dom.minidom.parse( "G:/manifest/default.xml" )
root = dom.documentElement

#仓库地址,访问不了可以使用清华源https://aosp.tuna.tsinghua.edu.cn/
prefix = git + " clone https://android.googlesource.com/"
suffix = ".git"

if not os.path.exists(rootdir):
os.mkdir(rootdir)

#遍历default.xml文件下的project节点,拿到path属性值也就是子项目名称,拼接完整url地址,调用call方法执行git clone url下载
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)
  1. 执行python脚本自行下载


打开命令行输入 ​​python download_android_platform_src.py​​ 回车就会自行下载,剩下的就是等待下载完成。


说明:


  1. ​python download_android_platform_src.py​​脚本就是使用python脚本dom语法遍历manifest/default.xml文件的project节点,找到path就是项目名称,然后拼接前缀下载地址,再调用call方法执行git clone url进行自行下载
  2. 访问https://android.googlesource.com是需要vpn的,如果网络问题可以再对应地方改为清华源https://aosp.tuna.tsinghua.edu.cn/
  3. 上面脚本网上找到。。。我也不会写,不过看得懂一点点意思。。。记录一下后面备用吧,多谢。。。





举报

相关推荐

0 条评论