---
title: "windows xp 中cygwin 下载android源码"
author: "喧嚣求静"
date: "2012-06-12T15:08:00Z"
tags: []
categories: ["移动开发"]
slug: "windows-xp-cygwin-android"
draft: false
lastmod: "2012-06-14T17:45:25Z"
id: 1559143
url: "https://913.iteye.com/blog/1559143"
---

1. 安装Cygwin。因为repo脚本的运行必须在linux下，因此我们要安装Cygwin。Cygwin是一个在Windows平台下运行的Unix模拟环境，[点击这里下载](http://www.cygwin.com/ "点击这里下载")。
2. 安装Cygwin的过程中可以选择要安装的包，以下是我们要安装的包：  
   1、Net -&gt; curl；  
   2、Devel -&gt; git* (git, git-completion, git-gui, gitk)；  
   3、Libs -&gt; libreadline6, libiconv2；  
   4、Editors -&gt; vim  
   5、Python -&gt; python。
3. ```
   $ mkdir ~/bin
   $ PATH=~/bin:$PATH
   ```
4. ```
   $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
   $ chmod a+x ~/bin/repo
   ```
   
   4
5. ```
   $ mkdir WORKING_DIRECTORY
   $ cd 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
   ```
6. ## Getting the files
   
   To pull down files to your working directory from the repositories as specified in the default manifest, run
7. ```
   $ repo sync
   ```

 

 

 

按照上面的方法，下载时，可能报连接超时，这是因为，android源码，默认下载是用匿名方式的，google为了某种性能和管理目的，做了限制，像一 般的，动态公网IP就 可能下载不了。为此，google提供了认证方式下载。

 

 

## Using authentication

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](https://android.googlesource.com/new-password) 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
```

也就是，

第一步，去google上产生认证信息，点击上面的"the password generator"

![](http://dl.iteye.com/upload/attachment/0069/4812/2c4595da-b80f-36ff-8e46-cf3ed678ce4a.jpg)

第二步：在cygwin当天用户目录下，新.netrc文件，并把产生的认证信息，填入。

![](http://dl.iteye.com/upload/attachment/0069/4814/4ab7f575-8450-38a3-99d3-622f3b5abc94.jpg)

第三步 ：使用此方式，初始化repo:

   $ repo init -u [https://android.googlesource.com/a/platform/manifest](https://android.googlesource.com/a/platform/manifest)  
第四步:

   repo sync

最终挂机6个多小时，下载完成，给个图片让学友们看看

![](http://dl.iteye.com/upload/attachment/0069/4816/82c83807-a16d-379d-aad4-64c6598f15d3.jpg)

 

1. 参考来源：
2. [http://source.android.com/source/downloading.html](http://source.android.com/source/downloading.html)
3. [http://www.2eggs.org/?p=97](http://www.2eggs.org/?p=97)
4. [http://www.cnblogs.com/mandroid/archive/2011/06/06/2073473.html](http://www.cnblogs.com/mandroid/archive/2011/06/06/2073473.html)
5. [http://blog.rexzhao.com/2011/11/29/Google-Code-set-netrc.html](http://blog.rexzhao.com/2011/11/29/Google-Code-set-netrc.html)

[http://my.oschina.net/armsky/blog/55644?p=1#rpl\_267635548](http://my.oschina.net/armsky/blog/55644?p=1#rpl_267635548)