一、如何下载安卓系统源码

 

Android 是一个适用于移动设备的开源操作系统以及由 Google 主导的相关开源项目。此网站和 Android 开源项目 (AOSP) 代码库可为您提供所需信息和源代码,供您创建定制的 Android 操作系统版本,将设备和配件移植到 Android 平台,同时确保您的设备符合兼容性要求,从而让 Android 生态系统维持良好稳健的运行环境,以便更好地服务于数百万用户。 

作为一个开源项目,Android 的目标是避免出现任何集中瓶颈(即没有任何行业参与者可一手限制或控制其他任何参与者的创新)。为此,Android 被打造成了一个适用于消费类产品的完整高品质操作系统,并配有可定制源代码,该代码可移植到几乎所有设备以及所有用户均可使用的公开文档中(英文网址:source.android.com;简体中文网址:source.android.google.cn)。

在公开文档中有关于源码的下载方法: https://source.android.google.cn/setup/downloading

敲黑板内容:

              你可以按照公开文档的下载方法下载源码,但是环境需要在linux下,那么windows如何下载呢,这里提供两种方案,中心思想是一样的。

一、模拟Linux环境:

          1.下载 Cygwin安装windows下的Linux模拟环境,用谷歌的Repo,repo 是一款工具。,然后就是一路的下一步(注意:如果第一次安装,你需要选install from internet,然后就是选安装位置,还有临时文件的位置和连接网络的设置,这些都默认就可以.关键的一步是选择要安装的库和程序,以下这几个是要安装的:

Net -> curl

Devel -> git,git-completion,git-gui,gitk

Libs -> libreadline6,libiconv2

Editors -> vim

扫描二维码关注公众号,回复: 6415958 查看本文章

Python -> python

如果不好找,你可以在上面的Search上搜索.

2.下载Repo

启动Cygwin,然后cd /bin,切到bin目录执行

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

下载repo到bin目录.然后执行

chmod a+x repo赋予它可执行的权限.

初始化仓库:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

如果需要某个特定的 Android 版本:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1

同步源码树(以后只需执行这条命令来同步):

repo sync

二、自制脚本下载:

下载git,安装 官方下载:https://git-scm.com/downloads/
下载python,安装 官方网址:http://www.python.org
打开Git Bash,执行命令,我是放在c盘的,路径可自定义
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
输入命令,切换到manifest目录
cd manifest
Git tag 列出android各个分支版本
下载android-cts-4.0_r1系统源码,输入下面命令,如果要下载其他版本源码,checkout git tag列出的版本号即可
git checkout android-cts-4.0_r1
checkout之后,manifest/default.xml文件中记录的就是android-cts-4.0_r1系统各个模块的路径,
下面就轮到python出场了,实现源码的批量下载
执行此脚本的前提是已经执行了git checkout,选择好了要下载的Android源码版本,按照以下源码请自行修改脚本。

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

#downloaded source path  
rootdir = "你的下载源码路径"  

#git program path  
git = "你的git路径/git.exe"
dom = xml.dom.minidom.parse("你的defalut路径/manifest/default.xml")  
root = dom.documentElement  

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)  


执行这个脚本之后将会自动下载源码

猜你喜欢

转载自blog.csdn.net/dongheli/article/details/86622475