Window10 下载AOSP(Android源码) 亲测有效

前言

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

可是我就想在 Windows 中使用 Source Insight 看看源代码,当然可以!
准备环境

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

1. 安装 git

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

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

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

2. 安装 Python (安装完后使用cmd一定要检测检测环境变量是否配置、是否安装成功,环境变量一般是自动配置的)

官网: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

    这时运行后的 目录下会出现一个 manifest 目录,进入此目录,里面除了 git 的配置目录外,clone 下来了一个 default.xml 文件和还有两个文件应该(然后运行完  git checkout xxxxx  命令后会只有.git和default.xml两个文件夹)。

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

去这里(没梯子进不去的) https://source.android.com/source/build-numbers.html#source-code-tags-and-builds

找到想要的版本分支,并复制(进不去往下看版本分支,通过命令进去)。

//切换到manifest目录

cd manifest
//没有梯子,使用 git branch -a 查看所有分支,找到想要的分支
git branch -a
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 = "D:/android_source_code/Android_6_0_1"

 

# 2. 设置 git 安装的路径

git = "C:/Develop/Git/bin/git.exe"

# 3. 修改为第一步中 manifest 中 default.xml 保存的路径

dom = xml.dom.minidom.parse("D:/android_source_code/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 脚本开始下载(在manifest 目录下只有.git和default.xml两个文件夹后在打开cmd命令,先检测pytnon是否安装然后cmd进入文件 python_download.py所在位置,运行.py文件)

你就静静的等待下载,一天、两天很漫长不用管他了让他自己下就ok了

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夢鑰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值