ubuntu下载android4.1源码------重传脚本很有效

来源:互联网 发布:ubuntu怎么用中文 编辑:程序博客网 时间:2024/04/20 11:21
详细手册参见:http://source.android.com/source/index.html

1、搭建下载和编译环境
①安装sun-java6-jdk,由于ubuntu官方软件源中已经不包含sun-java6-jdk,需要自己下载安装
②安装相关包,

32bit系统如下:
[html] view plaincopyprint?
  1. $ sudo apt-get install git-core gnupg flex bison gperf build-essential \  
  2. zip curl zlib1g-dev libc6-dev libncurses5-dev \  
  3. x11proto-core-dev libx11-dev libreadline5-dev libz-dev \  
  4. libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \  
  5. libxml2-utils xsltproc  

64bit系统如下:
[html] view plaincopyprint?
  1. $ sudo apt-get install git-core gnupg flex bison gperf build-essential \  
  2. zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \  
  3. x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \  
  4. libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \  
  5. libxml2-utils xsltproc  

2、下载源码
①Installing Repo
Make sure you have a bin/ directory in your home directory, and that it is included in your path:
[html] view plaincopyprint?
  1. $ mkdir ~/bin  
  2. PATH=~/bin:$PATH  

Download the Repo script and ensure it is executable:
[html] view plaincopyprint?
  1. $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo  
  2. $ chmod a+x ~/bin/repo  

②Initializing a Repo client
Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:
[html] view plaincopyprint?
  1. $ mkdir WORKING_DIRECTORY  
  2. $ cd WORKING_DIRECTORY  

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.
[html] view plaincopyprint?
  1. $ repo init -u https://android.googlesource.com/platform/manifest  

To check out a branch other than "master", specify it with -b:
[html] view plaincopyprint?
  1. $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1  

Android相关版本以及分支信息参见:http://source.android.com/source/build-numbers.html

③Getting the files
To pull down files to your working directory from the repositories as specified in the default manifest, run
[html] view plaincopyprint?
  1. $ repo sync  

出现问题如下:
1、执行repo sync后,提示使用git-core 1.7.2或者更高版本,然后使用ubuntu 10.04的sudo apt-get install git-core安装的版本为1.7.0

解决方法:
打开bin目录下的repo文件,将以下语句
[html] view plaincopyprint?
  1. MIN_GIT_VERSION = (1, 7, 2)     # minimum supported git version  
改为:
[html] view plaincopyprint?
  1. MIN_GIT_VERSION = (1, 7, 0)     # minimum supported git version  

2、总是提示http请求失败
error: Failed to connect to 2404:6800:4008:c01::52: Network is unreachable while accessing https://android.googlesource.com/platform/frameworks/compile/libbcc/info/refs  
fatal: HTTP request failed  
error: Failed to connect to 2404:6800:4008:c01::52: Network is unreachable while accessing https://android.googlesource.com/platform/frameworks/compile/linkloader/info/refs  
fatal: HTTP request failed

解决方法:
Using authentication

Google官方指出服务器访问基本是匿名的,为了防止连接过多(指内网/虚拟机),对同一IP地址的连接数做了一定的限制。看来是用gmail帐号进行认证。这样的话,在公司网络内或者用虚拟机下载的话,会经常遇到下载失败的问题。

The first step is to create a password from [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:
[html] view plaincopyprint?
  1. $ repo init -u https://android.googlesource.com/a/platform/manifest  

3、出现在下载过程中卡住的问题


解决方法:
结束此次下载后重新执行 $repo sync


=============== end =================


PS:在下载过程中出现下载失败时,再次执行repo sync就行了。
为了使用方便,可以使用shell脚本循环执行(shell脚本中的$?表示上一个命令的执行结果)

[html] view plaincopyprint?
  1. #!/bin/bash    
  2. echo "======start repo sync======"    
  3. repo sync    
  4. while [ $? == 1 ]; do    
  5. echo "======sync failed, re-sync again======"    
  6. sleep 3    
  7. repo sync    
  8. done  


经过一晚上的下载终于还是成功了~~~