最近想研究一下android,因此想去下载一下android的源代码。下面记录一下Android源代码下载的过程,以帮助一下需要的朋友。
-
下载Android源代码首先需要搭个梯子,或者请国外朋友下载。
具体方法这里不详述了,网上很多。
-
源代码下载到的步骤:
-
首先打开终端。(Ctrl + Alt + T)
-
安装git工具
-
$ sudo -s
apt-add-repository ppa:git-core/ppa
apt-get update
apt-get install git
git --version # 检查git的版本
```
* 新建一个文件夹用来保存源代码,并进入这个文件夹中:
```
mkdir android_src
```
* 下载repo工具,建立一个bin目录,用来放置下载好的repo文件
```
mkdir bin
cd bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > repo
chmod a+x repo # 修改他的权限:
cp repo /bin/ //为了方便的使用repo的命令
```
我在这个地址上下载下来的repo文件有问题,没法使用。因此在另外一个地址下载了一个:
```
curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo"> repo
```
* 下载源代码:
```
repo init -u https://android.googlesource.com/platform/manifest //初始化repo
// 或者,你想指定下载某一分支的话,可以在上面的命令后面指定:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r1
// 分支的名称可以在 https://android.googlesource.com/platform/manifest/+refs 里面查看。
repo sync
// 这时候就可以静待代码下载好了。
```
一些问题和解决方案:
-
同步代码时因为网络原因可能会经常断线,可以使用下面的脚本来做个脚本文件,让它中断后,又自动下载
!/bin/bash
echo "=========start repo sync=============="
repo sync
while [ $? == 1 ]; do
echo "======sync failed, re-sync again======"
sleep 3
repo sync
done
```
而后修改权限,执行就可以了
-
repo sync的时候包含的一个错误:
fatal: '../platform/abi/cpp.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
error: Cannot fetch platform/abi/cpp
```
解决方案:
在.repo目录下的manifest.xml里找到fetch属性, 将 `fetch="git://Android.git.linaro.org/"`成`fetch= "https://android.googlesource.com/"`下载就更快了,基本是你的宽带的峰值:
网友评论