编译Android14 AOSP记录

AOSP编译

编译环境

  • VirtualBox虚拟机 ubuntu 24.04
  • 磁盘空间500G
  • 内存:16G
  • swap空间:64G

事前准备

安装下载AOSP的依赖

#安装git
sudo apt-get install git
#配置环境变量
mkdir ~/bin
PATH=~/bin:$PATH

#安装cul
sudo apt-get install curl

#下载repo并设置权限:
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo

#安装python3
sudo apt-get install python3

安装编译AOSP的依赖

#安装jdk
sudo apt-get install openjdk-11-jdk
#安装编译所需的依赖包
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

这里遇到个问题,因为使用的ubuntu24.04,找不到git-core,libncurses5,lib32ncurses5-dev,所以修改如下:

  • git-core改为git
  • 24.04上libncurses5已经废弃了,使用apt-cache search libncurses命令搜索代替的库,搜索到libncurses6
  • 24.04上lib32ncurses5-dev已经废弃了,使用apt-cache search lib32ncurses命令搜索代替的库,搜索到lib32ncurses6

所以,最终使用如下命令安装依赖库。

sudo apt-get install git gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses6 lib32ncurses6 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

因为我们安装的是libncurses6,找不到libncurses.so.5,在后续编译的时会出现如下错误

error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
20:47:34 ninja failed with: exit status 1

所以采用符号链接,使用更高版本来代替。方式如下:

  1. 使用命令找到libtinfo.so.6libncurses.so.6的位置。

find /usr -name "libtinfo.so.6"
find /usr -name "libncurses.so.6"
  1. 根据输出的的位置创建符号链接
#libtinfo.so.6 符号链接
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
#libncurses.so.6 符号链接
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6 /usr/lib/x86_64-linux-gnu/libncurses.so.5
  1. 确认符号链接
ls -l /usr/lib/x86_64-linux-gnu/libtinfo.so.5
ls -l /usr/lib/x86_64-linux-gnu/libncurses.so.5

下载AOSP

mkdir android14
cd android14
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-14.0.0_r28
repo sync

编译AOSP

选择想要编译的镜像,最开始我选择的是aosp_x86_64-eng,但是后续运行模拟器时会产生问题,建议加入sdk_phone_x86_64-eng,后使用sdk_phone_x86_64-eng进行编译。

source build/envsetup.sh 
lunch //根据输出选择要编译的镜像编号
make -j6

编译阶段卡死

采用ubuntu24.04虚拟机来编译aosp的,使用make直接编译最后阶段不知道为什么会卡死,清理编译缓存后,重新使用make -j6就编译成功了。

运行模拟器

开启虚拟化

提示 ERROR | x86 emulation currently requires hardware acceleration
需要开启虚拟化,参考链接:https://blog.csdn.net/qq_44982815/article/details/111559823

缺少userdata-qemu.img

最开始编译的是aosp_x86_64-eng,编译成功后,运行模拟器时提示缺少userdata-qemu.img,输出如下:

Could not open '/root/aosp/out/target/product/generic_x86_64/userdata-qemu.img': No such file or directory
  • 经过查阅资料说aosp版本的镜像不会生成userdata-qemu.img,都建议编译sdk_phone_x86_64镜像,但是执行lunch后所输出的可编译列表并没有sdk_phone_x86_64。
  • 修改build/make/target/product/AndroidProducts.mk 文件,在COMMON_LUNCH_CHOICES 中增加 sdk_phone_x86_64-eng和sdk_phone_arm64-eng 。重新编译就出现sdk_phone_x86_64-eng和sdk_phone_arm64-eng 的选项了。
COMMON_LUNCH_CHOICES := \
    aosp_arm64-eng \
    aosp_arm-eng \
    aosp_x86_64-eng \
    aosp_x86-eng \
    sdk_phone_x86_64-eng \
    sdk_phone_arm64-eng \

参考文章:
https://zhuanlan.zhihu.com/p/705716442
https://zhuanlan.zhihu.com/p/703829482

清理AOSP编译缓存,重新编译 sdk_phone_x86_64-eng

#根目录
source build/envsetup.sh
make clobber
#根目录 
make clean 
#kernel目录
make mrproper

模拟器运行成功,但是黑屏

发现使用Android Studio的模拟器可以成功运行,所以打算使用Android Studio运行编译出的镜像来运行模拟器。

  1. Android13及以上使用 make emu_img_zip命令来打包生成镜像文件。完成后会输出镜像压缩包的所在目录,例如: /aosp/out/target/product/emulator_x86_64/sdk-repo-linux-system-images-eng.username.zip
source ./build/envsetup.sh
lunch sdk_phone_x86_64-eng
make -j6 #如果已经编译成功无需再执行该条命令
make emu_img_zip
#完成后会输出镜像包的路径

在这里插入图片描述在这里插入图片描述

  1. android studio使用生成的镜像启动模拟器
    根据输出的镜像文件目录,找到压缩包,把解压出来的x86_64文件夹里的内容复制到Android Studio模拟器所在目录。然后就成功运行模拟器
    在这里插入图片描述
    在这里插入图片描述

参考文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值