##1.配置git
# 安装git
sudo apt-get install git
# 配置账号信息
git config --global user.name "xxx"
git config --global user.email "xxx"
##2.配置repo
# 下载repo
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
# 如果同步时出现无法访问,可以修改REPO_URL
REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'
##3.同步源码
按照清华源的方法,使用每月更新的初始化包
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
tar xf aosp-latest.tar
cd aosp
repo sync -j8 # 正常同步一遍即可得到完整目录,-j 指定线程数,一般不要太大
aosp-latest.tar压缩包大约有165G,同步成功后如图:
##4.源码编译
source build/envsetup.sh
# 指定机器型号sdk_phone_x86_64,电脑模拟器可以运行
lunch sdk_phone_x86_64
# 直接lunch是看不到这个选项的,实际上是存在的,可通过ls build/make/target/product/sdk_phone*查看
m -j8
编译成功后通过emulator命令运行模拟器,效果如图
##5.常见错误
-
error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
suo apt-get install libncurses* 安装相应库
-
qemu-system-armel: Could not open ‘/media/wdp/Seagate/source/Android12/aosp/out/target/product/generic/userdata-qemu.img’: No such file or directory
lunch sdk_phone_x86_64 这个即可
-
模拟器打开后电脑卡死 或者出现Emulator terminated with exit code 139
推测是电脑硬件加速导致的,可以在启动模拟器的时候指定为软件加速,命令为
emulator -gpu swiftshader_indirect
##6.参考文档
AOSP官网
使用 Android 模拟器虚拟设备
Android 镜像使用帮助