网上关于这块大部分教程都是无效的,由于墙的缘故,没法使用官方提供的下载连接,我这里使用了清华大学的镜像,是可以顺利将 AOSP 下载下来。若是你尚未安装 Ubuntu,请看《VirtualBox 安装 Ubuntu》。html
Repo 是一款工具,可以让您在 Android 环境中更轻松地使用 Git,首先须要安装 Git:python
sudo apt-get install git
建立 bin,并加入 path:android
mkdir ~/bin PATH=~/bin:$PATH
下载 repo:git
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
错误:bootstrap
Command 'curl' not found, but can be installed with: sudo apt install curl
须要安装 curl,执行命令sudo apt-get install curl
进行安装。bash
注意:命令 apt
在低版本 Ubuntu 不行,本教程统一使用命令 apt-get
。curl
权限设置:ide
chmod a+x ~/bin/repo
输入命令repo
,提示:工具
/usr/bin/env: "python": 没有那个文件或目录
须要安装 python,执行命令sudo apt-get install python
安装,再次输入命令repo
,提示以下即 repo 安装成功:ui
error: repo is not installed. Use "repo init" to install it here.
创建工做目录 AOSP,命令:
mkdir AOSP cd AOSP
初始化仓库:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
错误1
error.GitError: manifests var: *** 请告诉我你是谁。 运行 git config --global user.email "you@example.com" git config --global user.name "Your Name" 来设置您帐号的缺省身份标识。 若是仅在本仓库设置身份标识,则省略 --global 参数。
没有设置身份,要使用 Gerrit 代码审核工具,您须要一个与已注册的 Google 账号关联的电子邮件地址:
git config --global user.email "wuxiaolong.me@gmail.com" git config --global user.name "WuXiaolong"
其余邮箱应该也是能够的。
错误2
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle fatal: error [Errno 101] Network is unreachable
由于 repo 运行过程当中会尝试访问官方的 git 源更新本身,若是想使用 tuna 的镜像源进行更新,将以下内容复制到你的~/.bashrc
里,而后重启终端模拟器。
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
错误3:
curl: (22) The requested URL returned error: 404 Not Found Server does not provide clone.bundle; ignoring.
为何会出现此种 log ?
在经过 Git 的 HTTP 协议下载最新数据以前,Repo 尝试下载预先打包的捆绑文件以引导每一个 git。
原文:Repo attempts to download a prepackaged bundle file to bootstrap each git prior to downloading the most recent data via Git's HTTP protocol.
若是捆绑文件不可用(如本例所示),Repo 将忽略它并继续进行,换句话说,不要注意这一点。
原文:If a bundle file isn't available (like in this case), Repo will ignore it and proceed anyway. In other words, don't pay any attention to this.
最后,如何取消 download clone.bundle ?
只须要 在repo 添加一个参数 --no-clone-bundle,以下:
可经过 repo
repo init --no-clone-bundle repo sync --no-clone-bundle
若是须要某个特定的 Android 版本(列表):
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.0.0_r1
提示如下,即 init 成功:
Your identity is: WuXiaolong <wuxiaolong.me@gmail.com> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in /media/disk/Project/AOSP
若是没有指定版本,如何知道下载好的 AOSP 是什么版本?
找到build/make/core/version_defaults.mk
文件打开,搜索PLATFORM_SDK_VERSION
,找到了 PLATFORM_SDK_VERSION := 28
,从 SDK 版本能够知道 AOSP 版本是 9.0,我下载的就是最新的。
同步源码树(之后只需执行这条命令来同步):
repo sync
而后等待下载完毕:
正在检出文件: 100% (1709/1709), 完成. 正在检出文件: 100% (9492/9492), 完成.在检出文件: 2% (251/9492) 正在检出文件: 100% (617/617), 完成.正在检出文件: 17% (106/617) 正在检出文件: 100% (15779/15779), 完成.检出文件: 7% (1251/15779) 正在检出文件: 100% (29/29), 完成. 正在检出文件: 27% (8/29) Syncing work tree: 100% (568/568), done.
最后整个源码大小 27.2 G。
https://source.android.google.cn/setup/
个人公众号:吴小龙同窗,欢迎交流~