1.编译环境构建
- 安装所需的软件包:
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ 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
2.配置手机设备的驱动文件
(1).查找源代码版本对应的代号
安卓Aosp源码中支持很多个设备的镜像编译,在编译之前需要配置对应设备依赖的驱动文件。此处下载的源码版本为:android-12.0.0_r3。对应安卓源码代号为:SP1A.210812.016.A1。具体源代码版本对应的代号以及支持的手机设备可以如下官网中查找:https://source.android.google.cn/setup/start/build-numbers。如下是该官网中找到的本编译版本结果。如下所示:
(2).下载对应手机型号的驱动配置文件
Google已为Aosp源码中支持的设备提供了对应的驱动文件支持。在官网:https://developers.google.cn/android/drivers可以找到对应系统版本和手机设备的驱动文件。此处需要编译的设备为pixel 3手机,手机系统版本为:android-12.0.0_r3,代号为:SP1A.210812.016.A1。在驱动官网找到对应的驱动文件如下:
点击页面中的"Link"下载对应的驱动文件包,并分别解压到源码根目录。如下所示:
/home/qiang/AospCode/Aosp12$ ls -la extract-*
-rwxr-x--x 1 qiang qiang 263013256 Sep 23 2021 extract-google_devices-blueline.sh
-rwxr-x--x 1 qiang qiang 1094338 Sep 23 2021 extract-qcom-blueline.sh
/home/qiang/AospCode/Aosp12$
/home/qiang/AospCode/Aosp12$
(3).执行驱动shell提取脚本
分别在终端执行extract-google_devices-blueline.sh和extract-qcom-blueline.sh脚本提取设备对应的驱动文件。该脚本执行完成之后,会自动在源码目录vendor中生成设备对应的驱动文件相关配置文件。命令执行如下:
qiang@ubuntu:~/Aosp11$ ./extract-google_devices-blueline.sh
qiang@ubuntu:~/Aosp11$ ./extract-qcom-blueline.sh
注意事项:
执行以上两个脚本之后,会显示一个文本协议,需要按*"Enter"键拉到底部,然后输入"I ACCEPT"的信息之后才能提取成功。如下所示:
3.源码编译
执行如下命令进行Pixel 3设备的镜像编译。命令如下:
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ source build/envsetup.sh
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_barbet-userdebug
4. aosp_blueline-userdebug
5. aosp_blueline_car-userdebug
Which would you like? [aosp_arm-eng] 4
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_PRODUCT=aosp_blueline
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-Ubuntu-20.04.6-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SP1A.210812.016.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/google/crosshatch hardware/google/av hardware/google/camera hardware/google/interfaces hardware/google/pixel hardware/qcom/sdm845 vendor/google/camera vendor/qcom/sdm845 vendor/google/interfaces vendor/google_devices/common/proprietary/confirmatioui_hal vendor/google_nos/host/android vendor/google_nos/test/system-test-harness vendor/qcom/blueline/proprietary
============================================
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ make -j6
以上命令说明:
-
source build/envsetup.sh命令初始化编译环境。
-
lunch命令列举当前源码支持的设备编译列表。由于此处的测试机为pixel 3,对应系统源码设备代号为:blueline,所以选择:3. aosp_blueline-userdebug进行编译。
-
make -j6表示开启6个并行任务数进行编译,此处j6可以根据电脑处理器进行调整。
以上命令编译的镜像为userdebug镜像,具有root权限和调试功能。如果想编译user模式镜像(user类型的镜像权限受限,适用于生产环境)。可以参考如下命令执行编译。
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ source build/envsetup.sh
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ lunch aosp_blueline-user
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_PRODUCT=aosp_blueline
TARGET_BUILD_VARIANT=user
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-Ubuntu-20.04.6-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SP1A.210812.016.A1
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/google/crosshatch hardware/google/av hardware/google/camera hardware/google/interfaces hardware/google/pixel hardware/qcom/sdm845 vendor/google/camera vendor/qcom/sdm845 vendor/google/interfaces vendor/google_devices/common/proprietary/confirmatioui_hal vendor/google_nos/host/android vendor/google_nos/test/system-test-harness vendor/qcom/blueline/proprietary
============================================
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$
qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$ make -j6