編譯Android中的module

參考:

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

android 幾個快速編譯images指令


 第一次下載好Android源代碼工程後,我們通常是在Android源代碼工程目錄下執行make命令,經過漫長的等待之後,就可以得到Android系統鏡像system.img了。以後如果我們修改了Android源代碼中的某個模塊或者在Android源代碼工程新增一個自己的模塊,是不是還是執行make命令呢?答案是否定的,Google爲我們準備了另外的命令來支持編譯單獨的模塊,以及重新打包system.img的命令。在繼續學習Android源代碼之前,就讓我們先來看看這個命令吧。

      一. 首先在Android源代碼目錄下的build目錄下,有個腳本文件envsetup.sh,執行這個腳本文件後,就可以獲得一些有用的工具:

      USER-NAME@MACHINE-NAME:~/Android$ .  ./build/envsetup.sh

      注意,這是一個source命令,執行之後,就會有一些額外的命令可以使用:

      - 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.
      這些命令的具體用法,可以在命令的後面加-help來查看,這裏我們只關注mmm命令,也就是可以用它來編譯指定目錄的所有模塊,通常這個目錄只包含一個模塊。
      二. 使用mmm命令來編譯指定的模塊,例如Email應用程序:
      USER-NAME@MACHINE-NAME:~/Android$ mmm packages/apps/Email/
      編譯完成之後,就可以在out/target/product/generic/system/app目錄下看到Email.apk文件了。Android系統自帶的App都放在這具目錄下。另外,Android系統的一些可執行文件,例如C編譯的可執行文件,放在out/target/product/generic/system/bin目錄下,動態鏈接庫文件放在out/target/product/generic/system/lib目錄下,out/target/product/generic/system/lib/hw目錄存放的是硬件抽象層(HAL)接口文件,後面的文章裏面,我們會陸續提及到,敬請關注。
      三. 編譯好模塊後,還要重新打包一下system.img文件,這樣我們把system.img運行在模擬器上時,就可以看到我們的程序了。
      USER-NAME@MACHINE-NAME:~/Android$ make snod
      四. 參照Ubuntu上下載、編譯和安裝Android最新源代碼一文介紹的方法運行模擬器:
      USER-NAME@MACHINE-NAME:~/Android$ emulator
      這樣一切就搞定了。

Android比較重要的三個img文件:

make systemimage - system.img

make userdataimage -userdata.img

make ramdisk - ramdisk.img

make snod - 快速打包system.img

(with thiscommand, it will build a new system.img very quickly. well, youcannot use “make snod” for all the situations. it would not checkthe dependences. if you change some code in the framework whichwill effect other applications)

因為
system.img 是 從 out/target/product/xxxx/system 做出來的。
如果改了 這個 folder 的內容,想要重新產生 system.img。不要管 system folde 裡面的 file 的dependency,可以用 snod 這個 target:

make snod




發佈了27 篇原創文章 · 獲贊 6 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章