如何获取android源代码

   研究Android的内部机理,源代码是必不可少的。大多数blog都推荐使用google提供的repo工具来获取Android源码,不过尝试多次 后未能完成。repo过程中问题多多:权限问题,gitserver主动断开连接,以及偶尔还有G_F_W干扰......

  当前的Android代码托管在两个地方: https://github.com/android https://android.googlesource.com 之前在 android.git.kernel.org上也有托管,不过现在重定向到了 https://android.googlesource.com 好在都支持git访问。

  google提供的repo工具实际上是一个内部操作git工具来简化操作Android源码的Python脚本。经过尝试,直接使用git工具在ubuntu下可以实现cloneAndroid源码。下面介绍一下方法:

1. 获取当前的在github上托管的Androidgitrepositories :

github页面为: https://github.com/android/following 。不过这个页面不支持通过 wget"https://github.com/android/following "或者curl" https://github.com/android/following "的方式访问,错误信息如下:

这样一来,获取这个页面内容并解析出其中的 gitrepositories就需要手工完成了。好在方法也很简单:浏览器中打开这个页面,然后"查看源文件"并保存为文本文件,比如保存为"android_git.html"。最后,通过下面的一行脚本来取出Androidgitrepositories.

?
grep -o "<span class=\"repo\">.*</span>" ./android_git.html | cut -d ">" -f2 | cut -d "<" -f1 > android_git.txt

2. 基于第1步获取的Androidgitrepositories来生成clonegit的脚本 :

执行如下的一行awk脚本

?
awk 'BEGIN{i=1; print "#!/usr/bin/env bash" }{ print "\n\necho \"begin clone android git ["i"]: " $1 "\""; print "git clone http://github.com/ " $1 ".git"; print "echo \"finish clone android git ["i"]: " $1 "\"" ; i=i+1; }' ./android_git.txt > git_clone_android.sh

现在用于cloneandroidgit的脚本生成好了,一共有103个gitrepository.

3. 执行git_clone_android.sh这个脚本即可

整体Android源码的代码量是相当庞大,完成所有的clone任务后,大概占用了7G磁盘空间,历时20多个小时,这是在网速比较快的情况下达到的效果:

其间也有许多问题,比如多次出现如下的错误:

如何获取android源代码

这个时候需能做的只能是"tryagain"了。

需要说明的是"不要试图同时并发执行多个gitclone命令",这样会导致大量出现上面贴图中的错误, 另外,整个clone过程中耗时最多的gitrepository如下:

kernel_common.gitkernel_msm.gitplatform_frameworks_base.gitplatform_prebuilt.git 其中platform_prebuilt.git是google提供的预编译好的二进制文件,包含:各种库文件,jar包,可执行程序等等,如果只是阅读Android源代码,这个gitrepository可以不用clone.

更多相关文章

  1. Android中Handler源码解析(一)
  2. 2011.06.07(2)——— android 调试android源码包下的package应用的
  3. 基于ffmpeg的Android播放器开源代码
  4. 【30篇突击 android】源码统计 十八
  5. Android消息处理机制——AsyncTask 源码解析
  6. Android ActionBar的源代码分析(一)

随机推荐

  1. 【Android(安卓)studio】Gradle download
  2. 关于LayoutInflate和View-infalte的参数
  3. android 镜像文件打包和解压
  4. 入门: 在Windows上搭建Flutter开发环境
  5. Android的嵌入式关系型SQLite数据库使用
  6. Android如何 如何关闭 DM-verity
  7. Android(安卓)开发——浅谈onInterceptTo
  8. 在Eclipse中配置Android的import和format
  9. Android(安卓)用KSOAP2 调用 webservice
  10. android用SharedPreferences保存登录账户