Windows下Android源码下载

前言

  • 每一年这个看源码的花样都在变,我记得前两年我下源码的时候还没这么多事,现在看个源码还得整整python了。
  • 本文基于文末的博客学习而来,环境win10,侧重点在于此过程中python爬的坑。
  • 本文不包含编译和查看环节,只教如何下载一个你想要的版本的源码到本地,下载好了怎么看,还需要你自己去摸索
  • 如果你嫌麻烦也可以直接在线看,这里推荐一个网址:http://androidxref.com/

安装Git

略,玩Android的Git还是得会把。

git bash clone

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

clone之后你当前文件夹会生成一个manifest文件夹。

切换你想要的源码分支

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

到这一步,Git的事就完事了,主要成果就是:default.xml,这个文件待会写在python下载脚本里。

Python爬坑

安装基本环境

这个python下载是去他官网下载。
https://www.python.org/downloads/
由于我是win10,他有3个版本,选择其中一个装上就行了,排除掉zip和web-installer,推荐安装剩下那个。

环境变量

就跟配Java环境变量似的。

准备好你的python下载脚本

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

# 1. 修改为源码要保存的路径
rootdir = "D:/androidSourceCode/Android_6_0_1"

# 2. 设置 git 安装的路径
git = "D:/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)

IDLE

按照上一步,打开开始菜单下的IDLE,看能否打开。

如果不能打开,你就接着本篇看,如果能打开,你可以去文末贴出来的博客链接去看。

PyCharm IDE安装

这个是JB出品的基于intelJ内核的python编译器,用起来跟studio大同小异,这里我说下我为啥用这个,因为我按照文末的博客并不能打开python自带的IDLE编辑器,那位博主也没有写如何解决,所以我只能用这个IDE进行脚本的运行。

至于这个在哪里下,百度PyCharm,下载下来不出意外会让你输激活码什么的,如果你有强迫症就去淘宝买个激活码,一般也就5块钱-10块钱之内,终生使用,但我这里目的就是为了跑一下源码下载的脚本罢了,我就选择的试用,反正也就跑跑完事。

唯一值得注意的事就是解释器的配置,这个跟我之前玩php storm的时候配解释器一个道理,说白了就是在这个IDE的settings里绑定一下你刚刚装的phthon.exe,具体看图。

运行加载脚本

用PyCharm新建一个py文件,内容就是上面你刚才准备的python脚本,然后右击,run。
然后就是等待源码下载完毕了。

参考

https://blog.csdn.net/freekiteyu/article/details/70939672

猜你喜欢

转载自blog.csdn.net/user11223344abc/article/details/80211989
今日推荐