由于之前做过一段时间的android开发,当时是2.3版本,开源代码里有很多值得学习的地方,所以想下载一套最新的android,方便以后学习和工作中涉及到相关内容时,能够借鉴和模仿。但


下载这套7.0.0的源码真是一波三折,各种坑,各种问题,各种百度。对于我这种只是想下载源码看看的人来说,真是折腾人,还好,最后成功下载下来了。



如果下载源码知识为了学习和参考,可以直接从我的网盘上下载,大约12G左右。(通过repo下载的源码大约60多G,但.repo文件夹有49G左右,去掉后,源码也就10多G了。)


https://pan.baidu.com/s/1gfbqBwJ 密码:wsu7




1.先是按照这个blog的方法下载,但是很不幸,遇到问题了。




遇到的错误如下:


syntax error near unexpected token `newline' /home/leo/bin/repo: line 2: `<!



解决方法如下:


curl http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo ~/bin/repo


repo init -u git://git.omapzoom.org/platform/manifest -b android-7.0.0_r21


参考:




2.接着,repo配置好了,repo sync时,碰到了类似下面的错误



fatal: ‘...git' does not appear to be a git repository"



解决方法:修改.repo目录下的manifest.xml文件,我的环境中,该文件中的


<remote name="aosp" fetch="git://git.omapzoom.org" />


中,fetch=""为空,添加我的镜像网址git://git.omapzoom.org


参考:



3.继续repo sync,又碰到了如下错误:


fatal: remote error: access denied or repository not exported



忘记是在哪个网站找到的解决方法了,原因就是manifest.xml文件中的某个项目的repository,在镜像库中并不存在。我的解决方法就是将不存在的注释掉。(可能是用的repo和7.0.0的有差异,所以不存在)


<!--project path="device/moto/shamu-kernel" name="device/moto/shamu-kernel" groups="device,shamu,broadcom_pdk" clone-depth="1" /-->



解决方法:将不存在的project直接注释掉。然后继续



4.继续,repo sync,接着碰到了下面的错误:


Out of memory, malloc failed (tried to allocate xxxxxx)



sync过程中,需要alloc一个500M多的内存,然后失败了。



问题原因:我的环境的原因是swap空间不够了,增大了swap空间后,问题解决。



参考: http://www.jb51.net/article/73597.htm



5.继续,然后遇到了如下问题:


android repo unable to write file xxxxx



问题原因:源码太大了,当时已经占用了50多G的空间,而我给虚机一共分配了60G,而且都挂载到了/根目录下,没有空间继续下载了。



解决方法:用Gparted扩展根目录的空间(比较麻烦,需要从U盘启动ubuntu,然后再扩展根目录空间)



6.以上问题陆续解决后,源码下载成功了。