AOSP(Android Open Source Project)安卓开源项目
cn可访问AOSP官网:https://source.android.google.cn/
由于网络限制,只能用国内镜像同步AOSP的代码。原本打算下载部分模块代码(为了方便阅读),但是github上AOSP缺少部分模块的代码。
Github上不完整的源代码:https://github.com/aosp-mirror
途径:
- 通过repo的init,获取repo目录
- 查看manifest文件夹下default.xml获取git仓库地址,选择性下载部分模块代码
一些问题及处理选择:
repo必须在Linux/mac下执行,那么可以选择安装常用虚拟机或者是WSL。这里选择采用WSL,在形式上感觉比用VM等工具安装虚拟机流程简单
WSL(Windows Subsystem for Linux,适于Linux的windows子系统)
计划步骤:
- 安装WSL
- 在wsl中repo init
- 获取git地址后,在windows下clone代码
一、源代码/镜像链接
Google官方AOSP源代码(不可访问):https://source.android.com/
AOSP官方文档 :https://source.android.google.cn/
Tsinghua
清华大学开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/
大学镜像汇总(大连东软信息学院提供)http://mirrors.neusoft.edu.cn/
二、安装WSL
官方教程:适用于 Linux 的 Windows 子系统安装指南 (Windows
10)https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
(一)安装与分发步骤
使用PowerShell(admin),采用WSL2
- 启用适用于Linux的Windows子系统,才能在Window上安装Linux分发
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- 确定WSL2所需的windows版本本机是否符合,否则不能使用WSL2
- 启用虚拟机功能
PS:安装WSL2之前,必须启用“虚拟机平台”可选功能dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- 以上两步骤的执行结果,需要重启
- 下载并安装Linux内核更新包
- 出现过一些问题执行msi,可能是关机和重启性能不同,关机环境还是没有配置
适用于 x64 计算机的 WSL2 Linux 内核更新包
- 将WSL2设为默认版本
wsl --set-default-version 2
- 微软商店安装所选的 Linux 分发
- 虽然没有写版本,但这里默认下载了最新版Ubuntu 20.04.1 LTS
- 设置新分发,设置用户名和密码
(二)定位WSL位置
以下的查询方式,感觉只有进行了操作才能在“网络”找到Ubuntu虚拟机,否则目录没有东西(应该是没有初始化完?)。然后一种简单粗暴的办法就是新建文件然后全文搜索文件能找到地址。
win+r
或者文件资源管理器输入\\wsl$
将WSL添加到网络位置方便访问
电脑内任意右键→“添加一个网络位置”
结果:
迁移WSL到非系统盘(工具 LxRunOffline)
# 使用 LxRunOffline.exe move 命令进行迁移,需要稍等一段时间后移动完成,如下。
# -n 指定你要迁移的系统名;
# -d 指定你新系统的迁移路径。
.\LxRunOffline.exe move -n Ubuntu-16.04 -d D:\VirtualMachine
# 使用LxRunOffline.exe get-dir查询子系统存储路径,如下:
.\LxRunOffline.exe get-dir -n Ubuntu-16.04
三、源代码下载
在安装完成的WSL中执行repo init
(一)安装repo并初始化仓库
参考:
清华AOSP:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
-
下载repo工具
mkdir ~/bin PATH=~/bin:$PATH # google的repo应该连接不上,建议替换(后文有问题场景) # https://mirrors.tuna.tsinghua.edu.cn/git/git-repo curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
问题1:python环境配置找不到
(1)shell原文:
$ mkdir code $ cd code/ ~/code$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest /usr/bin/env: ‘python’: No such file or directory ~/code$ python Command 'python' not found, did you mean: command 'python3' from deb python3 command 'python' from deb python-is-python3
(2)原因:找不到python命令。
/usr/bin/env: ‘python’: No such file or directory
- 查看应用列表系统安装了python3和python3.8,但是没有python
# 查看linux已安装应用列表 username@COMPUTERNAME:~$ apt list --installed Listing... Done ....(省略) python3.8/focal-updates,focal-security,now 3.8.2-1ubuntu1.2 amd64 [installed,automatic] python3/focal,now 3.8.2-0ubuntu2 amd64 [installed,automatic] ....
(3)解决:设置软连接python指向python3
username@COMPUTERNAME:~$ sudo ln -s /usr/bin/python3 /usr/bin/python
-
初始化
# 建立并进入工作目录(上一步的操作) mkdir code cd code # 初始化仓库 repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
问题2:repo镜像请求失败
(1)原文:
username@COMPUTERNAME:~$ cd code/ ~/code$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/A Downloading Repo source from https://gerrit.googlesource.com/git-repo fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle fatal: error [Errno 101] Network is unreachable fatal: cloning the git-repo repository failed, will remove '.repo/repo' OSP/platform/manifest Downloading Repo source from https://gerrit.googlesource.com/git-repo fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle fatal: error [Errno 101] Network is unreachable fatal: cloning the git-repo repository failed, will remove '.repo/repo'
(2)原因:无法连接到 gerrit.googlesource.com
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
(3)解决:rm原本的repo,下载清华repo镜像
- 参考:Git Repo 镜像使用帮助 https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/
# 下载 # 为了方便可以将其拷贝到你的PATH里 # (目前自己的PATH=~/bin:$PATH,所以repo也放在了bin目录下) curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo chmod +x repo # 更新 # repo的运行过程中会尝试访问官方的git源更新自己, # 使用tuna的镜像源进行更新,可以将如下内容复制到~/.bashrc里,并重启终端 export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
(4)再次运行,注意先设置username和email,否则报错,但是报错后提示在设置重新执行命令也能直接成功
(二)查看git仓库地址
-
repo/manifest/default.xml查看repo管理的分支名称
\wsl$\Ubuntu\home\username\code.repo\manifests
-
Dialer模块:https://aosp.tuna.tsinghua.edu.cn/platform/packages/apps/Dialer
-
Settings模块:https://aosp.tuna.tsinghua.edu.cn/platform/packages/apps/Settings
- 在下载的代码目录下.git/config里查看本分支地址
git clone https://aosp.tuna.tsinghua.edu.cn/platform/frameworks/opt/telephony