码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • # Windows 环境下载 Android 12源码


    前言

    Android 官网(该方式不适合 Windows 平台):https://source.android.com/source/downloading.html

    (备注自 2021 年 6 月 22 日起,安卓操作系统不再支持在 Windows 或 MacOS 上进行构建,如果要编译源码推荐先安装Ubuntu系统)

    可是我就想在 Windows 系统下 看看源代码,当然可以!

    准备环境

    1. 安装 git
    2. 安装 Python
    3. 自备梯子
    4. 硬盘剩余容量最好大于 150G

    1. 安装 git

    官网:https://git-scm.com/downloads/

    图形化工具:https://tortoisegit.org/

    什么?不会安装 git,那还看什么源码!自行百度!

    2. 安装 Python

    官网:https://www.python.org/downloads/

    安装参考:http://jingyan.baidu.com/article/c910274be14d64cd361d2dd8.html

    只需要安装好运行环境即可

    3. 自备梯子

    没有梯子?那就使用清华源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

    下载源码

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

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

    image.png

    这时 E:/androidSourceCode/ 目录下会出现一个 manifest 目录,进入此目录,里面除了 git 的配置目录外,clone 下来了一个 default.xml 文件。

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

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

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

    cd manifest
    //没有梯子,使用 git branch -a 查看所有分支,找到想要的分支
    git branch -a
    git checkout android-12.0.0_r34 //这里以 12.0 最后一个版本下载
    
    • 1
    • 2
    • 3
    • 4

    图2

    image.png

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

    将下面的代码复制,创建文件 python_download.py,并保存。

    import xml.dom.minidom
    import os
    from subprocess import call
     
    # 1. 修改为源码要保存的路径
    rootdir = "E:/androidSourceCode/Android12"
     
    # 2. 设置 git 安装的路径
    git = "C:/Develop/Git/bin/git.exe"
    
    # 3. 修改为第一步中 manifest 中 default.xml 保存的路径
    dom = xml.dom.minidom.parse("D:/androidSourceCode/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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    4. 执行 Python 脚本开始下载

    打开 Python 客户端

    图5

    打开上一步保存的 python_download.py 脚本文件

    图6

    点击 Run->Run Module 来运行脚本,或直接按F5运行。

    图7

    静静地等待下载完成吧。(我大概下载了一天一夜 ,12源码大概170G)

  • 相关阅读:
    【typora + gitee + picgo 搭建笔记图床】
    Linux 文件系统
    Python: 初识Python
    三、C#—变量,表达式,运算符(3)
    java通过Thread类实现多线程方法
    npm作用域包和版本
    C++:拷贝构造函数,深拷贝,浅拷贝
    挠场的科学丨三、特斯拉所来不及知道的「挠场」
    Unity3D之动态生成指定数量带间隔的地面
    如何隐藏删除去除桌面图标快捷方式的小箭头(含恢复方法)
  • 原文地址:https://blog.csdn.net/panghaha12138/article/details/132068347
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号