unbuntu终端中下载获取安卓(Android-4.0.1_r1)源代码

来源:互联网 发布:淘宝优惠券链接打不开 编辑:程序博客网 时间:2024/05/29 16:34

折腾了好几天unbuntu终端中安卓源代码的下载,今天终于是搞定了,参考了很多的文章,但是对于linux新手来说发现很多地方都不够详细,所以repo sync成功之后立马就发这篇博客以供新手玩弄,高手请绕道。下面是详细的步骤:

第一步:进终端,对于很多新手来说刚把unbuntu下下来之后终端都进不去,所以我就把这个步骤也包括进来,进去了直接跳到第二步。进终端有很多方法:1.直接快捷键按Ctrl+Alt+F1(F2、F3、F4均可)进去;2.直接双击“搜索您的电脑和在线资源”图标里面搜索“终端”即可。如图:


第二步:下载git和curl,命令如下:$ sudo apt-get install git-core curl。如图:


第三步:首先确保在你的home目录下面有一个bin目录,如果没有的话,执行下面命令:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
第四步:下载repo并确保它能够执行:

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
第五步:首先创建一个空目录用来保存工作文件:

$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
第六步:初始化repo客户端:

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

注意:这一步可能需要你的邮箱和密码,你需要在unbuntu中的浏览器中登录http://android.googlesource.com/new-password用你的gmail账号登录进去(国内大部分的ip都无法访问到国外的网站,这个时候可以考虑翻墙了,参考这篇文章http://jason-lam.lofter.com/post/17e8f0_64a9ab),然后将里面的脚本命令拷贝下来,看到网上很多人的都是marching开头的两行代码,其实我的并不是这样子的,而是这个:



把里面的脚本命令考到~/home目录下的.netrc,如果没有的话就新建一个,如图:

保存然后回到终端界面重新初始化repo客户端:

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

出现如下界面:



第七步:直接repo sync命令就可以下载安卓源代码了,如图:

说明大功告成!!

错误点(如果一路顺利按照前面的步骤把安卓源代码下下来的话这后面的错误点就不需要看了。):

1.首先容易出错的是第四步,这里由于网站或者本地网络的问题,可能会出现如下故障:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. root@mc-virtual-machine:~/android/bin# curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo  
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
  3.                                  Dload  Upload   Total   Spent    Left  Speed  
  4.   0     0    0     0    0     0      0      0 --:--:--  0:00:21 --:--:--     0  

下载会卡在一开始,而且卡住的概率很高。此时不必急着检查问题,可能是暂时的网络故障,可以ctrl + c 中断之后再次执行,尝试多次通常可解决此问题。

2.其次这一步还容易出错的地方。     

由于站点的问题,有些朋友在第六步执行repo init命令的时候会报错,如下:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. ./bin/repo: 行 1: 未预期的符号 `newline' 附近有语法错误  
  2. ./bin/repo: 行 1: `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'  

解决方法:更换repo下载站点,使用如下命令:
<pre class="best-text mb-10" code_snippet_id="336920" snippet_file_name="blog_20140509_9_9007086" name="code" style="font-size: 14px; font-family: tahoma, arial, sans-serif; white-space: pre-wrap; word-wrap: break-word;"><pre class="html" code_snippet_id="336920" snippet_file_name="blog_20140509_9_9007086" name="code"># curl http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo > ~/bin/repo    //获取repo
此时再次执行第六步可以得到第六步图示的结果。

3.在第六步的时候终端会询问如下问题:
[html] view plaincopyprint?
  1. root@mc-virtual-machine:~/android/bin/android_source# repo init -u https://android.googlesource.com/platform/manifest  
  2. error: Failed to connect to 2404:6800:4005:c00::52: Network is unreachable while accessing https://android.googlesource.com/platform/manifest/info/refs  
  3. fatal: HTTP request failed  
  4. fatal: cannot obtain manifest https://android.googlesource.com/platform/manifest  
由于访问是匿名的,为了防止连接过多,谷歌对同一IP地址的连接数做了一定的限制。这里需要用gmail帐号进行认证。通常在公司内部网络或者用虚拟机下运行的话,会经常遇到这个问题。这个时候就可以返回第六步按照“注意:”的操作来了。

4.最后一步在执行repo sync时,可能会报如下错误:

[plain] view plaincopyprint?
  1. fatal: '../platform/abi/cpp.git' does not appear to be a git repository fata  
这说明获取的路径有问题。

解决方法:进入安装repo的bin目录下一个叫.repo的目录,打开manifest.xml文件(命令gedit manifest.xml)并找到fetch属性,在我的文件中显示fetch="..",将fetch修改为fetch="git://Android.git.linaro.org/",保存并退出。再次执行repo sync 即可开始下载。

5.另外还有一个很少出现的错误。同样是在repo sync时,如果出现如下错误:

[html] view plaincopyprint?
  1. remote: Sending approximately 1.11 GiB ...  
  2. remote: Counting objects: 42, done  
  3. remote: Finding sources: 100% (42/42)  
  4. remote: Sending approximately 200.67 MiB ...  
  5. remote: Counting objects: 18, done  
  6. remote: Finding sources: 100% (18/18)  
  7. error: RPC failed; result=56, HTTP code = 2000 KiB/s       
  8. fatal: The remote end hung up unexpectedly  
  9. fatal: 过早的文件结束符(EOF)  
  10. fatal: index-pack failed  
  11. error: RPC failed; result=56, HTTP code = 200  
  12. fatal: The remote end hung up unexpectedly  
  13. fatal: early EOF  
  14. fatal: unpack-objects failed  
  15. error: RPC failed; result=56, HTTP code = 200  
  16. fatal: The remote end hung up unexpectedly  
  17. fatal: 过早的文件结束符(EOF)  
  18. fatal: index-pack failed  
  19. error: RPC failed; result=56, HTTP code = 200  
  20. fatal: The remote end hung up unexpectedly  
  21. fatal: 过早的文件结束符(EOF)  
  22. fatal: index-pack failed  
这个问题挺尴尬的,这是由于网络信号不顺畅造成的,比较Android官方网站设在国外,国内的网络常常会故障。大家可以留意一下在崩溃之前终端显示的下载速度,是不是由M编程KB ,然后慢慢变小,最后直接崩溃。。。

解决方法:

网络不顺通常是一时的,这里的办法除了换网之外只有反复执行 repo sync。当然这里完全不需要自己去反复执行,可以通过编写一个脚本程序,让计算机在下载崩溃后自动重新下载。在代码目录建立一个脚本(sh)文件,输入如下:

[plain] view plaincopyprint?
  1. #!/bin/bash  
  2.   
  3.  echo ¨================start repo sync===============¨  
  4.   
  5.  repo sync -f -j10  
  6.   
  7.  while [ $? == 1 ]; do  
  8.  echo ¨================sync failed, re-sync again=============¨  
  9.  sleep 3  
  10.  repo sync -f -j10  
  11.  done  

enjoying linux!!

0 0
原创粉丝点击