A_02.Aosp11源码编译
本节主要内容:
- 安卓11源码编译环境配置
- pixel 3手机源码驱动文件配置
- 安卓源码中编译Pixel 3设备手机镜像
1.编译环境构建
- 安装所需的软件包:
qiang@ubuntu:~/Aosp11$ 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-11.0.0_r46。对应安卓源码代号为:RQ3A.211001.001。具体源代码版本对应的代号以及支持的手机设备可以如下官网中查找:https://source.android.google.cn/setup/start/build-numbers。如下是该官网中找到的本编译版本结果。如下所示:
(2).下载对应手机型号的驱动配置文件
Google已为Aosp源码中支持的设备提供了对应的驱动文件支持。在官网:https://developers.google.cn/android/drivers可以找到对应系统版本和手机设备的驱动文件。此处需要编译的设备为pixel 3手机,手机系统版本为:android-11.0.0_r46,代号为:RQ3A.211001.001。在驱动官网找到对应的驱动文件如下:
点击页面中的"Link"下载对应的驱动文件包,并分别解压到源码根目录。如下所示:
qiang@ubuntu:~/Aosp11$
qiang@ubuntu:~/Aosp11$ pwd
/home/qiang/Aosp11
qiang@ubuntu:~/Aosp11$ 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
qiang@ubuntu:~/Aosp11$
qiang@ubuntu:~/Aosp11$
(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@ubuntu:~/Aosp11$ source build/envsetup.sh
qiang@ubuntu:~/Aosp11$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_blueline-userdebug
4. aosp_blueline_car-userdebug
5. aosp_bonito-userdebug
54. yukawa_sei510-userdebug
Which would you like? [aosp_arm-eng] 3
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
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.13.0-44-generic-x86_64-Ubuntu-20.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
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/qcom/blueline/proprietary
============================================
qiang@ubuntu:~/Aosp11$ make -j6
以上命令说明:
- source build/envsetup.sh命令初始化编译环境。
- lunch命令列举当前源码支持的设备编译列表。由于此处的测试机为pixel 3,对应系统源码设备代号为:blueline,所以选择:3. aosp_blueline-userdebug进行编译。
- make -j6表示开启6个并行任务数进行编译,此处j6可以根据电脑处理器进行调整。
以上命令编译的镜像为userdebug镜像,具有root权限和调试功能。如果想编译user模式镜像(user类型的镜像权限受限,适用于生产环境)。可以参考如下命令执行编译。
qiang@ubuntu:~/Aosp11$ source build/envsetup.sh
qiang@ubuntu:~/Aosp11$ lunch
You are building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_blueline-userdebug
Which would you like? [aosp_arm-eng] 3
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
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.13.0-44-generic-x86_64-Ubuntu-20.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
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/qcom/blueline/proprietary
============================================
qiang@ubuntu:~/Aosp11$ choosecombo
Build type choices are:
1. release
2. debug
Which would you like? [1] 1
Which product would you like? [aosp_blueline]
Variant choices are:
1. user
2. userdebug
3. eng
Which would you like? [eng] 1
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
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.13.0-44-generic-x86_64-Ubuntu-20.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ3A.211001.001
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/qcom/blueline/proprietary
============================================
qiang@ubuntu:~/Aosp11$ make -j6
ware/qcom/sdm845 vendor/google/camera vendor/qcom/sdm845 vendor/google/interfaces vendor/qcom/blueline/proprietary
============================================
qiang@ubuntu:~/Aosp11$ make -j6
视频地址:Aosp源码编译