栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

android 源码下载(windows)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android 源码下载(windows)

前提:保证系统已经装好了 git 和 python

1. 打开 Git Bash,用 git 克隆源代码仓库

git clone https://android.googlesource.com/platform/manifest.git
//没有梯子使用清华源
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git

 

 此时 D:Android codes 目录下多了一个名为 manifest的文件,其中由3个文件如下图:

2. 切换到想要的源码版本分支

去这里 https://source.android.com/source/build-numbers.html#source-code-tags-and-builds

找到想要的版本分支,并复制。

cd manifest
//没有梯子,使用 git branch -a 查看所有分支,找到想要的分支
git branch -a

 

git checkout android-11.0.0_r22 //这里以 11.0 最后一个版本下载

  

3. 使用 Python 执行脚本进行源代码下载

将下面的代码复制,创建文件 python_download.py并执行。脚本执行时间有点长请静静等候。

# -*- coding: utf-8 -*-
# @Time : 2022/7/12 19:54
# @Author : Red
# @FileName: down.py
# @Software: PyCharm

import xml.dom.minidom
import os
from subprocess import call

# 1. 修改为源码要保存的路径
rootdir = "D:/Android codes/manifest/android-11.0.0_r2"

# 2. 设置 git 安装的路径
git = "D:/Git-2.32.0-64-bit/Git/bin/git.exe"

# 3. 修改为第一步中 manifest 中 default.xml 保存的路径
dom = xml.dom.minidom.parse("D:/Android codes/manifest/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)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1012092.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号