需要在linux系统中下载,本文以ubuntu版本为例
1.安装git工具(版本控制工具,android代码是用git来维护的)
sudo apt-get install git
2.安装curl工具(利用URL语法在命令行方式下工作的文件传输工具)
sudo apt-get install curl
3.获取repo脚本并赋执行权限(repo是google写的一个执行git语句的脚本)
curl http://android.git.kernel.org/repo>~/repo
4.初始化库并下载代码
mkdir ~/android_src
cd ~/android_src
repo init –u git://android.git.kernel.org/platform/manifest.git
repo sync
上面这句命令会将当前主线上的最新版本的源代码库全部取下来,若只需要其中一部分代码,也可通过再加一个-b [branchname]参数来取指定的分支代码。
====================================================================================================================
以下内容来源于网络
如何下载Android源码
作者:陈刚,华清远见嵌入式学院讲师。
在下载源码之前需要安装如下软件包:
sudo apt-get install git-core
sudo apt-get install gnupg
sudo apt-get install sun-java5-jdk
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install gperf
sudo apt-get install libsdl-dev
sudo apt-get install libesd0-dev
sudo apt-get install build-essential
sudo apt-get install zip
sudo apt-get install curl
sudo apt-get install libncurses5-dev
sudo apt-get install zlib1g-dev
我们只需要安装 :
sudo apt-get install git-core
sudo apt-get install curl
其他软件包已经安装过了。
我们登录网址:http://source.android.com/source/downloading.html
看到
• Make sure you have a bin/ directory in your home directory, and that it is included in your path:
• mkdir ~/bin
• $ PATH=~/bin:$PATH
这一步是在家目录下创建 bin文件夹;并设置环境变量。
• Download the Repo script and ensure it is executable:
• $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
• $ chmod a+x ~/bin/repo
这一步是安装下载工具repo。
• 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:
• $ mkdir WORKING_DIRECTORY
• $ 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.
• $ repo init -u https://android.googlesource.com/platform/manifest
To check out a branch other than "master", specify it with -b:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
下面我们就开始android源码的下载,包括下载android4.0的源码。由于在编译android源码时,需要依赖N多个包,所以有必要安装一下。
安装完这些包之后,下面就要安装下载工具repo了,Repo是一个易用的管理android源码的工具,它可以用来下载、同步、上传Android项目源代码。安装步骤:
初始化Repo,并新建一个空目录以存放android源码:
完成repo init之后,它要求输入你的真实姓名和电子邮件地址来配置Repo。
初始化及配置结束之后,执行最后一步:repo sync -j4(由于repo sync主要是从服务器上取得源代码,所以执行时间会比较长,视网速而定,不过可以通过在repo sync后面加上-j4,来并行加速,4是并行的线程数,可以根据你的实际情况来定)。