Android源码Windows系统下载

Android源码Windows系统下载

一、前言

Android官网提供下载(支持Linux系统下载,不支持Windows系统下载),Android官网源码地址:https://source.android.com/source/downloading.html

由于只是使用Source Insight阅读和学习Android源代码,故通过以下方式在Windows系统中下载Android源码

二、环境准备

  • 安装git
  • 安装Python
  • 准备梯子
  • 硬盘剩余容量最好大于100G

三、下载源码

  1. 打开Git Bash,用git命令clone仓库

    git clone https://android.googlesource.com/platform/manifest.git
    //没有梯子使用清华源
    git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
    
  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-6.0.1_r79 //这里以 6.0 最后一个版本下载
    

    查看分支命令分支名

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

    创建python文件,并保存。

    import xml.dom.minidom
    import os
    from subprocess import call
     
    # 1. 修改为源码要保存的路径
    rootdir = "E:/workspace/android/android_source_14"
     
    # 2. 设置 git 安装的路径
    git = "E:/envir/Git/bin/git.exe"
    
    # 3. 修改为第一步中 manifest 中 default.xml 保存的路径
    dom = xml.dom.minidom.parse("E:/workspace/android/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脚本开始下载

    打开Python客户端

    python执行工具
    打开上一步保存的 python_download.py 脚本文件

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

  5. 等待下载源码,可以通过Ctrl+C取消下载部分模块代码或者执行脚本文件前修改default.xml文件

  • 19
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值