文章参照来源: http://source.android.com/source/downloading.html

一、window平台
关于在window平台下载Android源码,网上一般使用的是直接用git来下载。
比如:
http://wenku.baidu.com/view/a4f5f922482fb4daa58d4bb5.html
http://hendyyou.iteye.com/blog/1147738
这种方式最严重的问题是,对源码只能分块(git块)进行下载,而且块数很多。关键是现在google似乎没有提供了Android源码git块的详细列表。至少从网上文章给的链接我已经无法找到了哦。
我这里介绍的是通过在window平台上安装cygwin来模拟Linux环境来下载Android源码。
1.1、安装cygiwn.
首先需要安装Cygwin,关于此的详细内容请参考《cygwin安装详解》。
注意在安装Cygwin时,我们除了安装默认的组件,我们还需要安装bash, curl, git and python。
1.2、添加path路径
编辑.bash_profile添加path路径。.bash_profile文件位于“%cygwin安装目录%\home\%用户%”这个目录。比如我的就是“D:\tools\cygwin\home\rohu”
在.bash_profile文件中追加一行
export PATH=~/bin:$PATH
如果你访问互联网需要代理的话,还需要加上一个句命令。
假设代理服务器为“127.0.0.2::8080”,则命令为:
export http_proxy=127.0.0.2:8080

1.3、安装repo
通过Cygwin菜单Cygwin Terminal进入shell命令行。
输入以下命令:
mkdir ~/bin
curl --insecure https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
如果在国内,需要代理才能出去。我在假设代理服务器为“127.0.0.2::8080”
如果用代理的话,上面的命令就应该变为:
mkdir ~/bin
curl --insecure --proxy 127.0.0.2:8080 https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
到此repo脚本文件就安装好了。

1.4、配置git

在shell命令行,输入以下命令:
git config --global http.sslverify "false"如果在国内,需要代理才能出去。如果用代理的话,还需要加上一个句命令。
假设代理服务器为“127.0.0.2::8080”,则命令为:
git config --global http.proxy "127.0.0.2:8080"
到此git就配置好了。
1.5、安装repo客服端
1.5.1、新建一个工作目录WORKING_DIRECTORY,切换到该目录,以便存放Android源码:
在shell命令行,输入以下命令:
$ mkdir WORKING_DIRECTORY $ cd WORKING_DIRECTORY

15.2、Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.
$ repo init -u https://android.googlesource.com/platform/manifest 

To check out a branch other than "master", specify it with -b:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1

1.5.3、When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.在运行1.5.2的命令时,会弹出一个要求输入你的gmail邮箱的提示。最好输入有效的邮箱地址。

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.
在repo完成初始化后,你再当前目录下,应该能看到一个".repo"目录,manifest等就在该目录下。
如果你在这步遇到gpg验证出错,抛异常。那么请修改~/bin/repo文件的第187行来跳过gpg验证。
如下:
if _NeedSetupGnuPG():
      can_verify =False 
else:
can_verify = True

另外,我们可以通过在浏览器中输入https://android.googlesource.com/platform/manifest来获得各个版本对应的branch
由于访问这个地址很慢,我就把它的内容贴到了我博客上。具体请访问《Android发布版本所对应源码的branch》
1.6、取得源码

To pull down files to your working directory from the repositories as specified in the default manifest, run

$ repo sync 

The Android source files will be located in your working directory under their project names. The initial sync operation will take an hour or more to complete. For more about repo sync and other Repo commands, see Version Control.

执行上面的命令,Android的源码就开始下载了,它将被下载到".repo"目录的"projects"目录下。
如果已经下载了Android源码,但是现在需要想更新,便可以直接使用repo sync同步到本地。
可能会出现如下错误:
$ repo sync
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 2), reused 6 (delta 2)
Unpacking objects: 100% (6/6), done.
From git://github.com/richi-chen/Pandaboard-ICS-repo
   3ea7f09..11ecd6d  master     -> origin/master
   534d620..5fa74f5  omapzoom   -> origin/omapzoom
error: .repo/manifests/: contains uncommitted changes

网友解决:
richi 大虾:
to recover any uncommitted change, you should use 'git stash' and 'git clean -f -d'
for example: if you find it say there are uncommitted changes in .repo/manifests, you shoud 'cd .repo/manifests' and then 'git stash', 'git clean -f -d'

1.7、下载kernel源码
执行以下命令
git clone https://android.googlesource.com/kernel/common.git
将在Android目录下看到一个common目录,得到的common里面看不到文件,只有.git目录
进入common再执行git branch -a得到
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-2.6.39
  remotes/origin/android-3.0
  remotes/origin/master

这时我们可以通过执行git checkout android-3.0得到kernel3.0源码同样,

同理同过执行git checkout android-2.6.39将得到kernel2.6.39源码
二、Linux平台
在Linux平台下载Android源码,就要轻松的得多了。cygiwn都不用装。但是如果你的系统上还没有curl, git and python的话,请先安装它们。
2.1、添加path路径
编辑.bashrc添加path路径。.bashrc文件位于"/home/%用户%"这个目录
在.bashrc文件中追加一行
export PATH=~/bin:$PATH
在命令行执行以下命令:
source .bashrc
2.2、安装repo

请参照1.3
2.3、配置git
同1.4
2.4、安装repo客服端
同1.5
2.5、以匿名方式取得源码
同1.6
2.6、以授权方式取得代码
如果你需要向google提交对原生Android的修改。你就需要以授权方式取得代码。

By default, access to the Android source code is anonymous. To protect the servers against excessive usage, each IP address is associated with a quota.

When sharing an IP address with other users (e.g. when accessing the source repositories from beyond a NAT firewall), the quotas can trigger even for regular usage patterns (e.g. if many users sync new clients from the same IP address within a short period).

In that case, it is possible to use authenticated access, which then uses a separate quota for each user, regardless of the IP address.

The first step is to create a password from the password generator and to save it in ~/.netrc according to the instructions on that page.

The second step is to force authenticated access, by using the following manifest URI: https://android.googlesource.com/a/platform/manifest. Notice how the /a/directory prefix triggers mandatory authentication. You can convert an existing client to use mandatory authentication with the following command:

$ repo init -u https://android.googlesource.com/a/platform/manifest 

2.7、可能遇到的一些网络问题

When downloading from behind a proxy (which is common in some corporate environments), it might be necessary to explicitly specify the proxy that is then used by repo:

$ export HTTP_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>
 $ export HTTPS_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>

More rarely, Linux clients experience connectivity issues, getting stuck in the middle of downloads (typically during "Receiving objects"). It has been reported that tweaking the settings of the TCP/IP stack and using non-parallel commands can improve the situation. You need root access to modify the TCP setting:

$ sudo sysctl -w net.ipv4.tcp_window_scaling=0 $ repo sync -j1

2.8、下载kernel源码
同1.7
结束!
转自:http://hubingforever.blog.163.com/blog/static/1710405792011102622333130/

如何下载Android源码(window和Linux)相关推荐

  1. Window平台下载Android源码

    Android 10源码下载 想要研究Android 源码的同学可以用此方法进行下载.源码从清华大学开源软件镜像站下载. 使用Linux的同学直接参照清华镜像站提供的使用帮助即可,本文主要介绍在win ...

  2. 【Linux/Ubuntu学习6】unbuntu 下载android源码

    在Windows下安装Cygwin,通过Cygwin也可在Windows里通过本文的下载步骤下载Android源码. 以下为在Ubuntu下下载Google Android4.4源码的步骤: 1. 安 ...

  3. 下载Android源码流程(完整版)

      要在Linux环境下操作,要在Linux环境下操作,要在Linux环境下操作~~ 不要想在Windows环境下操作,因为会有各种问题.Windows环境的童鞋又不想装双系统的可以跟着下面的操作,L ...

  4. android源码下载过程的一些注意事项,windows下载android源码

    网上目前有很多下载android源码的方法,在linux下基本上用 repo 脚本,先repo init 然后在 repo sync一下 最后提取的时候的 使用 repo sync -l 一下. 所有 ...

  5. 下载Android源码

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://qxjerry.blog.51cto.com/947484/879952 文档说明 ...

  6. 下载Android源码(Google官方文档翻译)

    懒人一个,最讨厌英文文档,可惜中文教程又都残缺不全,只好自己动手翻译一个,第一次翻译,各种错误,翻译不当之处希望大家指出. 原文地址:http://source.android.com/source/ ...

  7. windows平台下载android源码

    最近在看<android内核剖析>,很多细节不具体看代码很难理解,记住了印象也不深,感觉还是跟着源码走一遍好些,回来下载android源码,遇到不少问题,终于开始下载了,整理下流程,鉴于网 ...

  8. android 清华镜像,清华镜像网站下载android源码并编译

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 下载android源码方法: 我的系统是ubuntu 18.04,主要参考了blog通过清华大学镜像下载Android源 ...

  9. Arndale Octa开发板下载android源码

    Arndale是由insignal公司开发制作的一款开发板,用了三星目前最先进的SoC Exynos5420,搭载了3GB的RAM,4G EMMC(这个有点坑),AX88796 10/100M网卡(略 ...

最新文章

  1. linux 命令安装redis
  2. 希尔伯特著名的第六问题 – 原来麦克斯韦早就有解?
  3. google的阴阳历转换查询
  4. word2010忽然无法撤销
  5. stl中各种容器的自定义比较函数
  6. swift-01-利用元组判断字符串出现次数
  7. 社会关系分析_肯德基加盟费分析!肯德基加盟流程!肯德基加盟条件2021
  8. android win10 style,不开玩笑,安卓可以体验 Windows 10 了
  9. Atitit 高性能架构之道 attilax著 艾龙 著 1. 应用服务与数据隔离 2 2. 负载均衡你问题 2 2.1. 用户的请求由谁来转发到到具体的应用服务器 2 2.2. 有什么转发的算法
  10. 计算机组装与维护要点,《计算机组装与维护》要点.ppt
  11. 如何将XML转换为HL7
  12. [Android6.0][MTK6737] 修改默认允许位置来源第三方应用安装
  13. 爪哇语:??????? 字面量,分类和存储库
  14. php服务器响应时间如何设置,php设置浏览器响应时间
  15. 分布式计算、云计算与大数据第十章
  16. SLA,SLO和SLI工程师指南
  17. SQL server 将不等于hit的全部删除
  18. 彩色matlab代码拷贝到word研究,matlab编辑器合并_彩色MATLAB代码拷贝到WORD研究
  19. 目标检测txt转xml
  20. 做seo为什么要了解网站?

热门文章

  1. LimeSDR+Ubuntu18.04实现GSM基站
  2. python 隐含波动率_什么是隐含波动率_隐含波动率的计算公式及平稳性
  3. 报错:BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:sprin
  4. flex布局青蛙游戏通关攻略
  5. SW2016提示cosworks.dll无法装入。
  6. 那些在Youtube上呼风唤雨,收入数十万美元的大神们
  7. 计算机考试客户端无法交卷,卓帆信息技术考试系统安装以后不能交卷,是什 – 手机爱问...
  8. 隆昌学电子计算机在什么地方,隆昌学种草莓的地方
  9. MyEclipse中项目出现红色感叹号原因分析
  10. 「产品中心」AMC系列三相多功能表