【0】准备环境:Linux or MacOS(也可以选择虚拟机里面安装ubuntu,请注意若是要编译Android源代码,Windows暂不支持).

Note:The source download is approximately 6GB in size. You will need 25GB free to complete a single build, and up to 90GB (or more) for a full set of builds.


【1】安装Git与curl:

$ sudo apt-get install git-core curl

根据官方介绍,如果是Ubuntu 12.04,请执行下面的操作:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386 \  g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown \  libxml2-utils xsltproc zlib1g-dev:i386

【2】安装Repo:一个使得Android与Git能够简单工作的工具。

  • 确保在你的home目录下有一个/bin的目录(这个目录其实也可以选择其他位置), 并且把它添加到你的Path路径下:

    $ mkdir ~/bin $ PATH=~/bin:$PATH 
  • 下载Repo脚本并确保它可执行:

    $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo $ chmod a+x ~/bin/repo
【3】初始化Repo:

  • 创建一个空的目录来存放你的源文件.你可以像下面一样创建一个目录:

    $ mkdir WORKING_DIRECTORY $ cd WORKING_DIRECTORY 
  • 执行repo init的操作来获取最新的源代码列表。

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

    然后使用 -b 来制定下载哪一个branch:(截至到目前,最新的版本是android-4.0.4_r1.2)

    $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.4_r1.2
  • 期间有可能会提示你输入账户名与邮箱,你可以输入你的Google帐号(其实可以随便填写一个)。
【4】开始同步下载:

  • 执行下面的命令既可(下载过程漫长)

$ repo sync

【5】可能遇到的问题:

如果你按上面的步骤执行后发现类似如下的错误:

Exception in thread Thread-3:Traceback (most recent call last):  File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner  self.run()  File "/usr/lib/python2.6/threading.py", line 484, in run  self.__target(*self.__args, **self.__kwargs)  File "/home/haili/android-4.0.4_r1.2/.repo/repo/subcmds/sync.py", line 200, in _FetchHelper  clone_bundle=not opt.no_clone_bundle)  File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 978, in Sync_NetworkHalf  and self._ApplyCloneBundle(initial=is_new, quiet=quiet):  File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1519, in _ApplyCloneBundle  exist_dst = self._FetchBundle(bundle_url, bundle_tmp, bundle_dst, quiet)  File "/home/haili/android-4.0.4_r1.2/.repo/repo/project.py", line 1583, in _FetchBundle  raise DownloadError('%s: %s ' % (req.get_host(), str(e)))DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out>  ...


那么解决方案如下:(学习自:http://blog.csdn.net/thl789/article/details/7524232)

1.浏览器登录https://android.googlesource.com/new-password,并用gmail帐号登录;

2.点击网页上的“允许访问”,得到类似:

machine android.googlesource.com login git-<userName>.gmail.com password <password>machine android-review.googlesource.com login git-<userName>.gmail.com password <password>

3.把上面那段信息(<userName>和<password>用自己得到的真实信息)追加到~/.netrc文件(此文件位于HOME/用户名/.netrc,若不存在可以新建这个文件)结尾;

4.下载地址的URI中添加字段a,如:https://android.googlesource.com/a/platform/manifest。

5.再执行上面的repo init与repo sync命令,即可开始下载。



请注意:学习自http://source.android.com/source/downloading.html,Android官方有可能更改获取源码的地址或方式,若按上面方法不能获取成功,请自行参考官方原文。谢谢!





更多相关文章

  1. android工程混淆和反编译
  2. 【Android】FragmentTabHost实现问题记录
  3. android-JNI
  4. android的system.img,userdata.img,ramdisk.img分析
  5. Android(安卓)文件系统路径
  6. android UI设计器-droiddraw
  7. Conversion to Dalvik format failed with error 1 in Android(
  8. Please ensure that adb is correctly located at...问题解决
  9. android 用ExpandableListView实现的文件目录树框架

随机推荐

  1. 分别在Linux和Android中用C语言写系统日
  2. Mac OS X下用Eclipse浏览和编译Android源
  3. Android之网络请求2————OkHttp的基本
  4. 高通平台android 环境配置编译及开发经验
  5. 图解android事件分发机制
  6. android创建隐藏文件或者文件夹,并对其读
  7. Android ListView 滑动背景为黑色的解决
  8. Android工程目录介绍
  9. Android基础教程(八)之仿百度谷歌搜索自
  10. Android 项目开发填坑记 - 使用 MultiDex