当前位置:操作系统 > 安卓/Android >>

单独编译Android源代码中的模块

单独编译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 choo易做图bo 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 choo易做图bo 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_TYP

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,