,我们成功下载了AOSP,很多时候我们不仅需要检查源码,还需要满足以下要求:
为了实现这个需求,我们需要编译系统源代码。
1. 编译系统概述
了解以下概念将使您对Android编译系统有一个大致的了解。
生成文件
Android平台的编译系统实际上是一个用Makefile编写的独立项目。 它定义了编译规则,实现了“自动编译”。 它不仅将分散在数百个Git仓库中的代码整合并统一编译,而且将产品按类别输出到目录中并打包到手机ROM中。 生成应用程序开发中使用的SDK、NDK等。
因此,Makefile编译的编译系统也可以称为Makefile编译系统。
Android.mk
Makefile编译系统的一部分,它定义了模块必要的参数,以便模块随平台一起编译。 通俗地说,它告诉编译系统使用什么规则来编译你的源代码并生成相应的目标文件。
忍者
Ninja是一个致力于速度的大型编译系统。 如果将其他编译系统视为高级语言,那么Ninja的目标就是汇编。
宋
Soong是微软替代之前Makefile编译系统,负责解析Android.bp文件并将其转换为Ninja文件
蓝图
Blueprint用于解析Android.bp文件并将其翻译成Ninja语句文件。
卡蒂
kati是微软专门为Android开发的一个小项目,基于Golang和C++。 目的是将Android中的Makefile转换为Ninja文件。
Android.bp
Android.bp是用于替换Android.mk的配置文件。
Android.mk、Ninja、Soong、Blueprint、kati、Android.bp的概念之间的联系是:
Blueprint负责解析Android.bp文件的内容。 Blueprint类似于一个库文件,用于处理相关的句型android源码 编译,而Soong则定义了如何处理相应的句型和命令执行。 总体来说,Soong使用Blueprint定义的Android.bp句型来完成对Android.bp的分析,并最终将其转换为Ninja文件。
Makefile 将被 kati 转换为 Ninja 文件。
随着Android项目变得越来越大,使用Makefile编译系统的时间也越来越长。 因此微软在Android 7.0中引入了Ninja来编译系统。 与Makefile相比,Ninja在大型项目管理方面速度越来越快。 并行方面具有突出的优势。
Makefile的默认文件名是Makefile或makefile,也常用.make或.mk作为文件后缀。 Ninja的默认文件名为build.ninja,其他文件的后缀为.ninja。 Makefile 和 Ninja 的区别在于,Makefile 是为开发而编译的,而 Ninja 是为其他程序生成的。 如果Makefile是Java语言,那么Ninja就是汇编语言。
2.源码编译方法
Android系统源码的编译方式有很多种,主要有以下几种:
需要注意的是,Docker最低支持的版本是Windows 7,建议在Windows 10环境下使用Docker,因为在Windows 7中需要使用Docker Toolbox和VirtualBox中的容器进行通信,效率相对较低低的。
考虑到大多数人的设备和易用性,本文讲解如何在Linux中直接编译系统源代码。 如果你的系统不是Ubuntuandroid源码 编译,你可以查看这篇文章。
3.准备编译环境
1.安装jdk8
sudo apt-get update
sudo apt-get install openjdk-8-jdk
2. 要使用ubuntu 14+,需要安装以下依赖项:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
3.设置处理器数量
在设置 --> 系统 --> 处理器选项中,设置处理器数量。 建议选择可设置的最大值。 这里设置为6。
4.源代码重组
编译就是编译整个Android源代码。 重新编译主要分为三个步骤,下面分别介绍。
1.初始化环境
在AOSP根目录下输入以下命令:
source build/envsetup.sh
// 编译前删除build文件夹A
make clobber
使用构建目录中的 envsetup.sh 脚本初始化环境,该脚本会导入其他执行脚本。
2.选择编译目标
输入命令:
lunch
Lunch命令是envsetup.sh中定义的命令,用于允许用户选择编译目标。
将输出以下信息:
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. aosp_car_arm-userdebug
8. aosp_car_arm64-userdebug
9. aosp_car_x86-userdebug
10. aosp_car_x86_64-userdebug
11. mini_emulator_arm64-userdebug
12. m_e_arm-userdebug
13. m_e_mips64-eng
14. m_e_mips-userdebug
15. mini_emulator_x86_64-userdebug
16. mini_emulator_x86-userdebug
17. uml-userdebug
18. aosp_cf_x86_auto-userdebug
19. aosp_cf_x86_phone-userdebug
20. aosp_cf_x86_tablet-userdebug
21. aosp_cf_x86_tablet_3g-userdebug
22. aosp_cf_x86_tv-userdebug
23. aosp_cf_x86_wear-userdebug
24. aosp_cf_x86_64_auto-userdebug
25. aosp_cf_x86_64_phone-userdebug
26. aosp_cf_x86_64_tablet-userdebug
27. aosp_cf_x86_64_tablet_3g-userdebug
28. aosp_cf_x86_64_tv-userdebug
29. aosp_cf_x86_64_wear-userdebug
30. cf_x86_auto-userdebug
31. cf_x86_phone-userdebug
32. cf_x86_tablet-userdebug
33. cf_x86_tablet_3g-userdebug
34. cf_x86_tv-userdebug
35. cf_x86_wear-userdebug
36. cf_x86_64_auto-userdebug
37. cf_x86_64_phone-userdebug
38. cf_x86_64_tablet-userdebug
39. cf_x86_64_tablet_3g-userdebug
40. cf_x86_64_tv-userdebug
41. cf_x86_64_wear-userdebug
42. aosp_marlin-userdebug
43. aosp_marlin_svelte-userdebug
44. aosp_sailfish-userdebug
45. aosp_walleye-userdebug
46. aosp_walleye_test-userdebug
47. aosp_taimen-userdebug
48. hikey-userdebug
49. hikey64_only-userdebug
50. hikey960-userdebug
Which would you like? [aosp_arm-eng]
这意味着您需要选择编译目标的格式。 编译目标的格式为BUILD-BUILDTYPE。 例如aosp_arm-eng的BUILD是aosp_arm,BUILDTYPE是eng。
其中,BUILD表示编译后的镜像可以运行在哪些环境,aosp表示Android开源项目,arm表示系统运行在基于arm的处理器上。