Android make 基礎(chǔ)

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


build 流程

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末隘截,一起剝皮案震驚了整個(gè)濱河市扎阶,隨后出現(xiàn)的幾起案子汹胃,更是在濱河造成了極大的恐慌,老刑警劉巖东臀,帶你破解...
    沈念sama閱讀 218,525評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件着饥,死亡現(xiàn)場離奇詭異,居然都是意外死亡惰赋,警方通過查閱死者的電腦和手機(jī)宰掉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來赁濒,“玉大人轨奄,你說我怎么就攤上這事【苎祝” “怎么了挪拟?”我有些...
    開封第一講書人閱讀 164,862評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長击你。 經(jīng)常有香客問我舞丛,道長,這世上最難降的妖魔是什么果漾? 我笑而不...
    開封第一講書人閱讀 58,728評(píng)論 1 294
  • 正文 為了忘掉前任球切,我火速辦了婚禮,結(jié)果婚禮上绒障,老公的妹妹穿的比我還像新娘吨凑。我一直安慰自己,他們只是感情好户辱,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,743評(píng)論 6 392
  • 文/花漫 我一把揭開白布鸵钝。 她就那樣靜靜地躺著,像睡著了一般庐镐。 火紅的嫁衣襯著肌膚如雪恩商。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,590評(píng)論 1 305
  • 那天必逆,我揣著相機(jī)與錄音怠堪,去河邊找鬼。 笑死名眉,一個(gè)胖子當(dāng)著我的面吹牛粟矿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播损拢,決...
    沈念sama閱讀 40,330評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼陌粹,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼!你這毒婦竟也來了福压?” 一聲冷哼從身側(cè)響起掏秩,我...
    開封第一講書人閱讀 39,244評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤或舞,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后蒙幻,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體映凳,經(jīng)...
    沈念sama閱讀 45,693評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,885評(píng)論 3 336
  • 正文 我和宋清朗相戀三年杆煞,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了魏宽。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片腐泻。...
    茶點(diǎn)故事閱讀 40,001評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡决乎,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出派桩,到底是詐尸還是另有隱情构诚,我是刑警寧澤,帶...
    沈念sama閱讀 35,723評(píng)論 5 346
  • 正文 年R本政府宣布铆惑,位于F島的核電站范嘱,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏员魏。R本人自食惡果不足惜丑蛤,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,343評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望撕阎。 院中可真熱鬧受裹,春花似錦、人聲如沸虏束。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽镇匀。三九已至照藻,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間汗侵,已是汗流浹背幸缕。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評(píng)論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留晰韵,地道東北人冀值。 一個(gè)月前我還...
    沈念sama閱讀 48,191評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像宫屠,于是被迫代替她去往敵國和親列疗。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,955評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容