Androidd源码非常庞大,由好几百个git仓库组成,是由repo工具来进行管理的。为了和AOSP的仓库兼容,我们也搭建使用repo工具管理的私有源码仓库。
在WSL2的Ubuntu 16.04环境中我们完成了Android 6.0源码的编译,在这个基础上,我们来搭建基于WSL2的Android代码仓库,和每日迭代编译的环境。
1.环境搭建
Android源码仓库的搭建,需要两台设备,一台作为Android源码仓库,一台作为客户端上传Android源码。我们把完成Android 6.0源码编译的Ubuntu 16.04作为客户端,另外重新创建一台Ubuntu 20.04作为Android源码仓库服务器。
打开"Microsoft Store"微软商城,搜索"ubuntu",即可搜索到多个ubuntu的发行版,选择免费的"Ubuntu 20.04 LTS"下载,下载完成后,在"Microsoft Store"微软商城直接启动Ubuntu 20.04。
在"Windows PowerShell(管理员)"中查看WSL的运行情况。
PS C:\WINDOWS\system32> wsl -l -v
NAME STATE VERSION
* Ubuntu-16.04 Running 2 #客户端,上传代码
Ubuntu-20.04 Running 2 #服务器,Android源码仓库
可以看到Ubuntu 20.04已经正常运行。
通过管理员Windows PowerShell给Ubuntu 20.04设置IP地址,把两个系统设置到同一个网段。
wsl -d Ubuntu-16.04 -u root ip addr add 172.19.110.237/24 broadcast 172.19.110.255 dev eth0 label eth0:1
wsl -d Ubuntu-20.04 -u root ip addr add 172.19.110.236/24 broadcast 172.19.110.255 dev eth0 label eth0:2
netsh interface ip add address "vEthernet (WSL)" 172.19.110.1 255.255.255.0
2.配置服务器
2.1 配置客户端repo
Android源码仓库搭建好之后,需要用repo工具验证,先配置repo。
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
repo工具初始化时,需要下载git-repo仓库,配置清华的源,可以加速下载。
vim ~/.bashrc
#在文件末尾添加REPO_URL
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
source ~/.bashrc
尝试运行一下repo命令,有python环境缺失的错误。Ubuntu 20.04中默认安装python3,没有python命令,做个软链接。
sudo ln -s /usr/bin/python3 /usr/bin/python
2.2 服务端启动git服务
WSL2的Ubuntu系统跟直接安装的Ubuntu系统在底层系统服务上有些差别,gitlab等开源系统运行有问题。简单起见,我们直接用git daemon启动git服务。
/usr/bin/git daemon --export-all --enable=receive-pack --reuseaddr --base-path=/home/yourname/repositories &
命令参数含义:
--export-all:使用该选项后,在git仓库