admin管理员组

文章数量:1576879

最近在看《android内核剖析》,很多细节不具体看代码很难理解,记住了印象也不深,感觉还是跟着源码走一遍好些,回来下载android源码,遇到不少问题,终于开始下载了,整理下流程,鉴于网上很多教程时间久了都会失效,本文截止14年4月18日亲测有效。

需要工具如下:

下载msysgit,安装     官方下载: http://download.csdn/detail/jason0539/7212993,  下载python,安装      官方网址: http://www.python   打开Git Bash,执行命令,我是放在d盘的,路径可自定义   cd D: git clone https://android.googlesource/platform/manifest.git     这里会遇到问题,说你连接不上站点,错误代码443 解决方案,在电脑的hosts文件中添加如下几行,不知道hosts在哪的自行百度  
74.125.31.82 www.googlesource

74.125.31.82 android.googlesource

203.208.46.172 cache.pack.google

59.24.3.173cache.pack.google


添加之后在重新执行上面的命令应该没问题,继续往下  

 

输入命令,切换到manifest目录

cd manifest

 

git tag 列出android各个分支版本

下载android-4.4系统源码,输入下面命令,如果要下载其他版本源码,checkout git tag列出的版本号即可

git checkout android-4.4.2_r1
checkout之后,manifest/default.xml文件中记录的就是android4.4系统各个模块的路径,     下面就轮到python出场了,这里用的是网上的一段python代码,实现源码的批量下载 执行此脚本的前提是已经执行了git checkout,选择好了要下载的Android源码版本,如果你的manifest文件不是D:/manifest/default.xml,还要把里面的git.exe的路经修改成你的安装路径,请自行修改脚本。 download-src.py源码:
import xml.dom.minidom
import os
from subprocess import call

#downloaded source path
rootdir = "D:/android-source"

#git program path
git = "D:/Program Files/Git/bin/git.exe"

dom = xml.dom.minidom.parse("D:/manifest/default.xml")
root = dom.documentElement

prefix = git + " clone https://android.googlesource/"
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)


执行这个脚本之后,就开始自动下载了,   截张图:   估计需要一段时间,耐心等待。
-------------------------------------15年7月28日更新------------------------------------------------------------
用公司电脑下代码,用的mac,流程跟上面有些不一样,但是还是会遇到网络问题,幸好买了VPN,没有浪费很多时间,想起来这里好多评论提到连接失败的问题
所以建议大家购买vpn,现在vpn服务有很多,自己任选都可以,
我自己在用云梯,你不介意的话可以用下面链接购买,便宜10块钱,同时我也能得到10元优惠,算互惠互利吧
http://protizi/?r=3a3de744a61437e8

------------------------------------16年2月17日更新------------------------------------------------------------- 现在推荐用清华镜像的下载,无需翻墙,速度也比较快,https://wiki.tuna.tsinghua.edu/MirrorUsage/android 但是还是推荐一下云梯哈,翻墙后方便很多,用此链接购买你我都能优惠10元 http://protizi/?r=3a3de744a61437e8

 

作者:jason0539

微博:http://weibo/2553717707

博客:http://blog.csdn/jason0539(转载请说明出处)

本文标签: 源码平台Windowsandroid