window环境下载Android系统源代码的方法
window环境下载Android系统源代码的方法
- 下载网址
网站的地址是:
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
- 准备环境
安装
git
环境、安装python
环境,这个自行百度下载安装
- 下载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
即可捡出最新的代码分支
- 编写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)
- 执行python脚本自行下载
打开命令行输入
python download_android_platform_src.py
回车就会自行下载,剩下的就是等待下载完成。
说明:
python download_android_platform_src.py
脚本就是使用python脚本dom语法遍历manifest/default.xml文件的project节点,找到path就是项目名称,然后拼接前缀下载地址,再调用call方法执行git clone url进行自行下载访问https://android.googlesource.com是需要vpn的,如果网络问题可以再对应地方改为清华源https://aosp.tuna.tsinghua.edu.cn/
上面脚本网上找到。。。我也不会写,不过看得懂一点点意思。。。记录一下后面备用吧,多谢。。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库