虚拟机环境准备
虚拟机及Ubuntu安装
VM 版本 VMware Workstation Pro 16
Ubuntu版本 ubuntu-22.04-desktop-amd64
Ubuntu软件源更换
清华源地址 :https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
配置构建环境
#更新源
sudo apt update
#下载安装Git:
sudo apt install git
#设置Git账户,
git config --global user.email "xxx@xxx.com"
git config --global user.name "xxx"
#安装Curl
sudo apt install curl
#安装Repo工具
mkdir ~/bin
PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
#创建工程目录
mkdir AOSP
cd AOSP
#修改repo地址(用文本编辑器)
if not REPO_URL:
REPO_URL = 'https://gerrit.googlesource.com/git-repo'
#改为:
if not REPO_URL:
REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'
源码下载和编译
初始仓库
根据需要去Android官网找对应源码版本
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b 源码版本
成功标志
出现这行就行了,下面的写的东西不用管]
开始同步
#在工程目录下创建脚本(可以先安装个vim )
vim down.sh
#脚本内容:
#!/bin/bash
repo sync -j4
while [ $? -ne 0 ]
do
echo "===========sync failed ,re-sync again==========="
sleep 3
repo sync -j4
done
#赋予权限
chmod a+x down.sh
#运行脚本
./down.sh
开始编译
#安装编译工具, 根据官方说明, 直接运行即可
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
#设置编译环境 (PS:每次关闭 Shell 之后都需要重新执行下面这个脚本,相当于配置了一下编译环境)
source build/envsetup.sh
#运行lunch ,选择设备
lunch
使用 lunch 选择要构建的目标。lunch product_name-build_variant 会选择 product_name 作为需要构建的产品,并选择 build_variant 作为需要构建的变体
官网查看设备build 配置模拟器是aosp_x86_64-userdebug
#可以输入编号也可以直接输入代号
lunch aosp_x86_64-userdebug
使用 m或make 构建所有内容。m 可以使用 -jN 参数处理并行任务。如果您没有提供 -j 参数,构建系统会自动选择您认为最适合您系统的并行任务计数。
make
运行模拟器
记得开启虚拟机的虚拟化引擎
emulator
参考:
https://zhuanlan.zhihu.com/p/486719177
https://zhuanlan.zhihu.com/p/548407780