美文网首页
Windows 环境下载 Android 源码

Windows 环境下载 Android 源码

作者: as_pixar | 来源:发表于2020-03-19 08:42 被阅读0次

    准备环境

    • 安装 git
    • 安装 Python
    • 自备梯子(可有可无)

    1. 安装 git

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

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

    2. 安装 Python

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

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

    ## 下载源码

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

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

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

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

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

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

    cd manifest
    //没有梯子,使用 git tag 查看所有分支,找到想要的分支
    git  tag  
    git checkout android-6.0.1_r79 //这里以 6.0 最后一个版本下载
    

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

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

    import xml.dom.minidom
    import os
    from subprocess import call
     
    # 1. 修改为源码要保存的路径
    rootdir = "E:/Android/source/Android_6_0_1"
     
    # 2. 设置 git 安装的路径
    git = "D:/Program Files/Git/bin/git.exe"
    
    # 3. 修改为第一步中 manifest 中 default.xml 保存的路径
    dom = xml.dom.minidom.parse("E:/Android/source/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)
    

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

    运行脚本后,静静地等待下载完成吧。

    相关文章

      网友评论

          本文标题:Windows 环境下载 Android 源码

          本文链接:https://www.haomeiwen.com/subject/wxhkyhtx.html