建议翻墙跟着官网操作,下载一下源
官网https://source.android.com/source/downloading
Installing Repo
Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see the Developing section.
To install Repo:
-
Make sure you have a bin/ directory in your home directory and that it is included in your path:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
-
Download the Repo tool and ensure that it is executable:
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
下载配置好repo后,创建目录然后sync源码
mkdir android_source2.3
cd android_source2.3
mkdir android_source2.3
cd android_source2.3
repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1 #下载android-2.3.1_r1源码
#下载哪个分之按个人需求,eg 如下是下载android-7.1.1_r13 的源码,#repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r13 #下载android-7.1.1_r13源码
repo sync
推荐执行如下shell脚本来替代repo sync
vim auto_repo.sh
---------------------------------
#!/bin/bash
for (( ; ; ))
do
repo sync -j16 #开更多job去sync代码,当然快慢取决于机器性能和网络
if [ $? == 0 ]; then
break;
fi
done
---------------------------------------
chmod a+x auto_repo.sh
./auto_repo.sh
然后执行repo start master --all #checkout 默认分支为本地master branch
代码下载完了接下来准备开始编译源码,如果你想在本地安装一堆包,配置各种JDK /OPENJDK的那好吧,当我什么都没说,但是如果想摆脱配置编译环境的烦恼,我推荐使用docker来编译android源码,真的是so easy,再也不需要配置环境了。docker编译源码的介绍在如下文。