閱讀696 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Android模塊化編譯

如果你隻需要修改某一個模塊的內容,但是卻每次都要執行make, 最後等待很長時間。
使用模塊編譯,那隻需要在你所在的模塊的目錄或者其子目錄,執行mm,便可以編譯出一個單獨的apk,這樣豈不快哉!
具體步驟:
        1)打開~/.baserc文件,加入source ~/I850/build/envsetup.sh. 加入你自己該文件所在的路徑,這樣就免去了每次啟動新的終端執行mm命令之前,需要引用此文件。
        2)完成步驟1之後,就可以在你的模塊裏麵隨意執行mm了,要想使用其他快速命令,可以查看envsetup.sh文件,比如cgrep,jgrep,resgrep在不同類型的文件裏麵進行相應的查詢。還有m,mmm等等
        3)還可以使用adb push 將你的apk push到模擬器或者手機終端,也可以在工程根目錄通過make -snod生成新的system.img




1、我們平常在編譯Android源碼,有時並不需要編譯整個Android源碼,而隻需要編譯模個模塊,這是可以使用mmm工具來編譯。

其使用方法是:mmm <dir>,如編譯frameworks下的所有文件,則可以這樣子:
. build/envsetup.sh && choosecombo 1 1 2 3 &&
export ANDROID_JAVA_HOME=$JAVA_HOME && mmm framwork
編譯出來的APK,但APK並不包含在system文件夾中,我們可以使用make snod 打包system文件夾,產生新的system.img。
$. build/envsetup.sh && help
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- 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:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest runtest_py setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver tapas tracedmdump
2、關於img文件說明
編譯android源碼之後,在out/target/product/generic一些文件: ramdisk.img、system.img、userdata.img、 system、 data、root
其中, system.img是由 system打包壓縮得到的, userdata.img是由 data打包壓縮得到的。
ramdisk.img是模擬器的文件係統,把ramdisk.img解壓出來可知道,ramdisk.img裏的文件跟root文件夾的文件基本一樣。
模擬器裝載ramdisk.img並解壓到內存,接著分別把system.img和userdata.img掛載到 ramdisk下的system和data目錄。我們編譯出來的應用程序就是放在system/app下的。用戶安裝的程序則是放在data/app下。

最後更新:2017-04-04 07:03:03

  上一篇:go 利用mm命令編譯Android模塊
  下一篇:go 字符編碼