1- adroid 演進(jìn)過程
Android編譯演進(jìn)過程:
- Android7.0之前 使用GNU Make
- Android7.0 引入ninja枫吧、kati强岸、Android.bp和soong構(gòu)建系統(tǒng)
- Android8.0 默認(rèn)打開Android.bp
-
Android9.0 強(qiáng)制使用Android.bp
Make 構(gòu)建系統(tǒng)得到了廣泛的支持和使用胶坠,但在 Android 層面變得緩慢鸭叙、容易出錯(cuò)衣形、無法擴(kuò)展且難以測試嘉抒。Soong 構(gòu)建系統(tǒng)正好提供了 Android build 所需的靈活性权埠。
2- android build 流程
build/ 目錄下
- blueprint:用于處理Android.bp榨了,編譯生成*.ninja文件,用于做ninja的處理
- kati:用于處理Android.mk攘蔽,編譯生成*.ninja文件龙屉,用于做ninja的處理
- make:文件夾還是原始的make那一套流程,比如envsetup.sh
-
soong:構(gòu)建系統(tǒng)满俗,核心編譯為soong_ui.bash
3 編譯環(huán)境初始化
source build/envsetup.sh
輸入指令hmm 就可以查看信息
Run "m help" for help with the build system itself.
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
Selects <product_name> as the product to build, and <build_variant> as the variant to
build, and stores those selections in the environment to be read by subsequent
invocations of 'm' etc.
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|arm64|x86_64|mips64] [eng|userdebug|user]
- croot: Changes directory to the top of the tree, or a subdirectory thereof.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- provision: Flash device with all required partitions. Options will be passed on to fastboot.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- mangrep: Greps on all local AndroidManifest.xml files.
- mgrep: Greps on all local Makefiles files.
- sepgrep: Greps on all local sepolicy files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
- allmod: List all modules.
- gomod: Go to the directory containing a module.
- pathmod: Get the directory containing a module.
- refreshmod: Refresh list of modules for allmod/gomod.
Environment options:
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
ASAN_OPTIONS=detect_leaks=0 will be set by default until the
build is leak-check clean.
- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
lunch 2
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=10
TARGET_PRODUCT=aosp_arm64
TARGET_BUILD_VARIANT=eng
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-4.15.0-137-generic-x86_64-Ubuntu-16.04.7-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=QD4A.200805.003
OUT_DIR=out
4-make 說明
通過soong執(zhí)行編譯構(gòu)建转捕,這里執(zhí)行make命令時(shí),main.mk文件把一些環(huán)境變量和目標(biāo)都配置好后唆垃,會(huì)執(zhí)行envsetup.sh中的make()進(jìn)行編譯五芝。
function make()
{
_wrap_build $(get_make_command "$@") "$@"
}
function get_make_command()
{
# If we're in the top of an Android tree, use soong_ui.bash instead of make
if [ -f build/soong/soong_ui.bash ]; then
# Always use the real make if -C is passed in
for arg in "$@"; do
if [[ $arg == -C* ]]; then
echo command make
return
fi
done
echo build/soong/soong_ui.bash --make-mode
else
echo command make
fi
}
build/soong/soong_ui.bash --make-mode
------->
[build/soong/soong_ui.bash] -------》 下面說明
# Save the current PWD for use in soong_ui
export ORIGINAL_PWD=${PWD}
export TOP=$(gettop)
source ${TOP}/build/soong/scripts/microfactory.bash
soong_build_go soong_ui android/soong/cmd/soong_ui -->生成soog_ui
cd ${TOP} --->return root
exec "$(getoutdir)/soong_ui" "$@"------>exec out/soong_ui --make-mode build
“echo build/soong/soong_ui.bash --make-mode ”
soong的編譯過程:
soong_ui.bash 調(diào)用流程:
可以看到include 了main.mk文件,從main.mk開始辕万,將通過include命令將其所有需要的.mk文件包含進(jìn)來枢步,最終在內(nèi)存中形成一個(gè)包括所有編譯腳本的集合,這個(gè)相當(dāng)于一個(gè)巨大Makefile文件渐尿。Makefile文件看上去很龐大醉途,其實(shí)主要由三種內(nèi)容構(gòu)成: 變量定義、函數(shù)定義和目標(biāo)依賴規(guī)則砖茸,此外mk文件之間的包含也很重要隘擎。
文件 | 作用 |
---|---|
build/make/core/main.mk | Build的主控文件,主要作用是包含其他mk凉夯,以及定義幾個(gè)最重要的編譯目標(biāo)货葬,同時(shí)檢查編譯工具的版本,例如如gcc劲够、clang宝惰、java等 |
build/make/core/config.mk | Build的配置文件欺殿,主要是區(qū)分各個(gè)產(chǎn)品的配置燎含,并將這些編譯器參數(shù)引入產(chǎn)品配置 BoardConfig.mk,同時(shí)也配置了一些編譯器的路徑等 |
build/make/core/definitions.mk | 最重要的 Make 文件之一,在其中定義了大量的函數(shù)绍些。這些函數(shù)都是 Build 系統(tǒng)的其他文件將用到的炒瘸。例如:my-dir淤堵,all-subdir-makefiles,find-subdir-files顷扩,sign-package 等拐邪,關(guān)于這些函數(shù)的說明請(qǐng)參見每個(gè)函數(shù)的代碼注釋。 |
build/make/core/dex_preopt.mk | 定義了dex優(yōu)化相關(guān)的路徑和參數(shù) |
5.工具鏈的關(guān)系
Android.bp --> Blueprint --> Soong --> Ninja
Makefile or Android.mk --> kati --> Ninja
(Android.mk --> Soong --> Blueprint --> Android.bp)
REF
https://blog.csdn.net/yiranfeng/article/details/109082489