單獨編譯Android原始碼中的模組

來源:互聯網
上載者:User

單獨編譯Android原始碼中的模組

第一次下載好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
執行命令如下:


fantasy@ubuntu:~/my_android$ . ./build/envsetup.sh


或者

fantasy@ubuntu:~/my_android$ source build/envsetup.sh


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

fantasy@ubuntu:~/my_android$ hmm
輸出為:


[plain]  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 

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 等目的是為了引用剛剛改動過的環境變數。

 

 

二、使用mmm編譯指定模組
以下是通過mmm編譯android中內建的一個實驗性的應用,命令如下:

fantasy@ubuntu:~/my_android$ mmm packages/experimental/CameraPreviewTest/


[plain]  ============================================ 
PLATFORM_VERSION_CODENAME=AOSP 
PLATFORM_VERSION=4.2.2.2.2.2.2.2.2.2 
TARGET_PRODUCT=full 
TARGET_BUILD_VARIANT=eng 
TARGET_BUILD_TYPE=release 
TARGET_BUILD_APPS= 
TARGET_ARCH=arm 
TARGET_ARCH_VARIANT=armv7-a 
TARGET_CPU_VARIANT=generic 
HOST_ARCH=x86 
HOST_OS=linux 
HOST_OS_EXTRA=Linux-3.8.9-x86_64-with-Ubuntu-10.04-lucid 
HOST_BUILD_TYPE=release 
BUILD_ID=OPENMASTER 
OUT_DIR=out 
============================================ 
make: Entering directory `/home/fantasy/my_android' 
target R.java/Manifest.java: VideoChatCameraTestApp (out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/src/R.stamp) 
Warning: AndroidManifest.xml already defines minSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest. 
Warning: AndroidManifest.xml already defines targetSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest. 
target Java: VideoChatCameraTestApp (out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes) 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes-jarjar.jar 
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/emma_out b/classes-jarjar.jar 
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes.jar 
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates proguard.classes.jar 
target Dex: VideoChatCameraTestApp 
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates proguard.classes.dex 
target Package: VideoChatCameraTestApp (out/target/product/generic/obj/APPS/VideoChatCameraTestApp_intermediates/package.apk) 
Warning: AndroidManifest.xml already defines minSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest. 
Warning: AndroidManifest.xml already defines targetSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest. 
 'out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes.dex' as 'classes.dex'... 
Processing target/product/generic/obj/APPS/VideoChatCameraTestApp_intermediates/package.apk 
Done! 
Install: out/target/product/generic/data/app/VideoChatCameraTestApp.odex 
Install: out/target/product/generic/data/app/VideoChatCameraTestApp.apk 

============================================
PLATFORM_VERSION_CODENAME=AOSP
PLATFORM_VERSION=4.2.2.2.2.2.2.2.2.2
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.8.9-x86_64-with-Ubuntu-10.04-lucid
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER
OUT_DIR=out
============================================
make: Entering directory `/home/fantasy/my_android'
target R.java/Manifest.java: VideoChatCameraTestApp (out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/src/R.stamp)
Warning: AndroidManifest.xml already defines minSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest.
Warning: AndroidManifest.xml already defines targetSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest.
target Java: VideoChatCameraTestApp (out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/emma_out b/classes-jarjar.jar
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes.jar
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates proguard.classes.jar
target Dex: VideoChatCameraTestApp
Copying: out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates proguard.classes.dex
target Package: VideoChatCameraTestApp (out/target/product/generic/obj/APPS/VideoChatCameraTestApp_intermediates/package.apk)
Warning: AndroidManifest.xml already defines minSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest.
Warning: AndroidManifest.xml already defines targetSdkVersion (in  http://schemas.android.com/apk/res/android); using existing value in manifest.
 'out/target/common/obj/APPS/VideoChatCameraTestApp_intermediates/classes.dex' as 'classes.dex'...
Processing target/product/generic/obj/APPS/VideoChatCameraTestApp_intermediates/package.apk
Done!
Install: out/target/product/generic/data/app/VideoChatCameraTestApp.odex
Install: out/target/product/generic/data/app/VideoChatCameraTestApp.apk
編譯完成之後,就可以在out/target/product/generic/data/app/VideoChatCameraTestApp.apk目錄下看到VideoChatCameraTestApp.apk檔案了。

 


註:

Android系統內建的App是放在目錄~/my_android/out/target/product/generic/system/app下。

另外,Android系統的一些可執行檔,例如:

C編譯的可執行檔,放在out/target/product/generic/system/bin目錄下,

動態連結程式庫檔案放在out/target/product/generic/system/lib目錄下,

硬體抽象層(HAL)介面檔案防砸out/target/product/generic/system/lib/hw目錄下。

 

  

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.