歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 單獨編譯Android源代碼中的模塊

單獨編譯Android源代碼中的模塊

日期:2017/3/1 9:55:53   编辑:Linux編程

第一次下載好Android源代碼後,通過在Android源代碼工程下執行make命令,然後得到Android的系統鏡像system.img.

那麼當我們修改了android源代碼中某個模塊或者android源代碼工程中新增了一個自己的模塊。此時可以用make命令進行重新編譯,不過重新編譯比較浪費時間。google提供了另外的命令來進行單獨模塊的編譯,以及重新打包到system.img鏡像中的命令。

以下介紹單獨編譯android中模塊的命令,以及打包system.img的命令。

一、首先,執行腳本文件 envsetup.sh

該文件在Android源代碼目錄下的build目錄中,在這個shell 腳本中定義了 hmm, croot, m, mm, mmm 等 function

執行命令如下:

www.linuxidc.com@Ubuntu:~/my_android$ . ./build/envsetup.sh

或者

www.linuxidc.com@ubuntu:~/my_android$ source build/envsetup.sh

在當前目錄下輸入命令hmm(android 4.2版本使用hmm,其他版本貌似使用的是help命令),顯示envsetup.sh提供命令

www.linuxidc.com@ubuntu:~/my_android$ hmm

輸出為:

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.


Look at the source to view more functions. The complete list is:
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mangrep mm mmm pid printconfig print_lunch_menu resgrep runhat runtest set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump

這些命令的具體用法,可以在命令的後面加-help來查看,這裡我們只關注mmm命令,也就是可以用它來編譯指定目錄的所有模塊,通常這個目錄只包含一個模塊。

注:

關於source

source 命令會把對應腳本中的內容讀取到當前的bash 解釋器中,在當前的執行環境中執行;其中定義的 function 以及通過 export 聲明的變量等在 source 執行結束之後依然存在於當前的bash 環境中。比如我們常用的 source .bashrc 或者 source /etc/profile 等目的是為了引用剛剛改動過的環境變量。

Copyright © Linux教程網 All Rights Reserved