Android
源码的开发、学习,官方推荐使用Ubuntu
或macOS
系统,下面在Ubuntu 12.04LTS
中学习Android 2.3
源码。
环境如下:
Host : macOS High Sierra(10.13.2)
VM : VMWare Fusion 10.1.0 (7370838)
Guest : Ubuntu 12.04.5LTS
首先,下载Android
源码到本地:
安装curl
、git
AOSP
下载工具repo
需要安装curl
和git
工具:
$ sudo apt-get install curl git
$ curl -V
curl 7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp smtp smtps telnet tftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
$ git --version
git version 1.7.9.5
下载repo
脚本
下载repo
脚本到本地,并赋予可执行权限:
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
被墙可以使用国内镜像:
$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o ~/bin/repo
$ chmod a+x ~/bin/repo
初始化工作目录
本地建立工作目录以便下载AOSP
源码:
$ cd ~
$ mdir WORKING_DIRECTORY
$ export WORKING_DIRECTORY=~/WORKING_DIRECTORY # 设置工作目录环境变量,后面方便引用
$ cd $WORKING_DIRECTORY
初始化工作目录
初始化工作目录,下载代码仓库及BUG修复的列表,默认下载master
分支:
$ repo init -u https://android.googlesource.com/platform/manifest
也可以使用-b
指定分支:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.7_r1
分支列表可以参看:源代码标记和版本。
被墙使用国内镜像:
首先修改repo
脚本,将REPO_URL
链接修改为:
REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
或者设置REPO_URL
环境变量:
$ export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
然后执行repo init
:
# master
$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
# 分支
$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-2.3.7_r1
等待代码同步到本地,如果中断,下次直接执行同步命令,可以继续下载,不用重新开始。
已有仓库修改源
如果已经使用repo sync
同步过代码,或者使用repo init
初始化过工作目录,可以打开工作目录下配置文件.repo/manifests.git/config
,将
url = https://android.googlesource.com/platform/manifest
修改为:
url = https://aosp.tuna.tsinghua.edu.cn/platform/manifest
即可切换仓库。
同步代码
执行同步命令:
$ repo sync
遇到的问题
下载源码的时候,出现了Fetching projects: 99% (169/170)
,repo
卡在99%,始终无法继续,Linux
中的解决方法,输入以下命令:
$ sudo sysctl -w net.ipv4.tcp_window_scaling=0