Android source build/envsetup.sh 该知道的细节

1. 前言

        在编译Android源码时,开始一定会初始化系统环境变量,两条熟悉的命令:

        source build/envsetup.sh

        lunch  xxx

       那这样子初始化,有什么作用呢,初始化环境变量后有哪些快捷开发指令可以用呢? 我们来总结一下。

2.  envsetup.sh命令

        执行 source build/envsetup.sh命令时,这里的envsetup.sh被link到了 build/make/envsetup.sh文件

 此时在终端输入 hmm 命令,如下:

home@home-MS-7B89:~/project/code$ hmm

Run "m help" for help with the build system itself.

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch:      lunch <product_name>-<build_variant>
              Selects <product_name> as the product to build, and <build_variant> as the variant to
              build, and stores those selections in the environment to be read by subsequent
              invocations of 'm' etc.
- tapas:      tapas [<App1> <App2> ...] [arm|x86|mips|arm64|x86_64|mips64] [eng|userdebug|user]
- croot:      Changes directory to the top of the tree, or a subdirectory thereof.
- m:          Makes from the top of the tree.
- mm:         Builds all of the modules in the current directory, but not their dependencies.
- mmm:        Builds all of the modules in the supplied directories, but not their dependencies.
              To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma:        Builds all of the modules in the current directory, and their dependencies.
- mmma:       Builds all of the modules in the supplied directories, and their dependencies.
- umake:     Call ninja directly to speed up build when there is no modifications to .mk or .bp files.
- provision:  Flash device with all required partitions. Options will be passed on to fastboot.
- cgrep:      Greps on all local C/C++ files.
- ggrep:      Greps on all local Gradle files.
- jgrep:      Greps on all local Java files.
- resgrep:    Greps on all local res/ xml files.
- mangrep:    Greps on all local AndroidManifest.xml files.
- mgrep:      Greps on all local Makefiles files.
- sepgrep:    Greps on all local sepolicy files.
- sgrep:      Greps on all local source files.
- godir:      Go to the directory containing a file.
- allmod:     List all modules.
- gomod:      Go to the directory containing a module.
- pathmod:    Get the directory containing a module.
- refreshmod: Refresh list of modules for allmod/gomod.

Environment options:
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
                 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
                 build is leak-check clean.
- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.

逐个解释说明一下:

命令

解释说明
lunch

lunch <product_name>-<build_variant>

选择<product_name>作为要构建的产品,<build_variant>作为要构建的变体,并将这些选择存储在环境中,以便后续调用“m”等读取。

tapas交互方式:tapas [<App1> <App2> ...] [arm|x86|mips|arm64|x86_64|mips64] [eng|userdebug|user]
croot将目录更改到树的顶部或其子目录。
m编译整个源码,可以不用切换到根目录

mm

编译当前目录下的源码,不包含他们的依赖模块

mmm

编译指定目录下的所有模块,不包含他们的依赖模块   例如:mmm dir/:target1,target2.

mma

编译当前目录下的源码,包含他们的依赖模块

umake当 .mk 或 .bp 文件没有修改时,直接调用 ninja 以加快构建速度。

mmma

编译指定目录下的所模块,包含他们的依赖模块

provision

具有所有必需分区的闪存设备。选项将传递给fastboot。

cgrep

对系统本地所有的C/C++ 文件执行grep命令

ggrep

对系统本地所有的Gradle文件执行grep命令

jgrep

对系统本地所有的Java文件执行grep命令

resgrep

对系统本地所有的res目录下的xml文件执行grep命令

mangrep

对系统本地所有的AndroidManifest.xml文件执行grep命令

mgrep

对系统本地所有的Makefiles文件执行grep命令

sepgrep

对系统本地所有的sepolicy文件执行grep命令

sgrep

对系统本地所有的source文件执行grep命令

godir

根据godir后的参数文件名在整个目录下查找,并且切换目录

allmod

列出所有模块

gomod

转到包含模块的目录

pathmod

获取包含模块的目录

refreshmod

刷新allmod/gomod的模块列表

2.1 croot 

        croot的中文翻译为“根”,大致意思就是回到工程代码的根目录,比如你在某个模块下面,想回到根目录,执行此命令:

home@home-MS-7B89:~/project/mount/cts/android11$ cd frameworks/base/packages/services/
home@home-MS-7B89:~/project/mount/cts/android11/frameworks/base/packages/services$ croot
home@home-MS-7B89:/mnt/mount/cts/android11$ 

2.2  gomod  <module>

        直接跳转到某个子模块,这个很方便切换查看模块代码

home@home-MS-7B89:/mnt/mount/cts/android11$ gomod Settings
home@home-MS-7B89:/mnt/mount/cts/android11/packages/apps/Settings$

2.3 pathmod <module>

        显示当前模块的路径 和 pwd 命令同样的意思

home@home-MS-7B89:/mnt/mount/cts/android11/packages/apps/Settings$ pathmod Settings
/mnt/mount/cts/android11/packages/apps/Settings

2.4  m  mm  mmm 

        编译整个工程,编译某个模块常用命令

编译指令解释
m在源码树的根目录执行编译
mm编译当前路径下所有模块,但不包含依赖
mmm [module_path]编译指定路径下所有模块,但不包含依赖
mma编译当前路径下所有模块,且包含依赖
mmma [module_path]编译指定路径下所有模块,且包含依赖
make [module_name]无参数,则表示编译整个Android代码

对于m、mm、mmm、mma、mmma这些命令的实现都是通过make方式来完成的。

mmm/mm编译的效率很高,而make/mma/mmma编译较缓慢;

make/mma/mmma编译时会把所有的依赖模块一同编译,但mmm/mm不会;

建议:首次编译时采用make/mma/mmma编译;当依赖模块已经编译过的情况,则使用mmm/mm编译。

2.5  umake

        当修改某个模块的代码,没有新增加新java文件,资源文件,没有修改Android.bp Android.mk,用此命令可以加速编译速度。

2.6  grep 搜索

        这些命令可以非常快捷,高效查找到目标文件

        jgrep   "findString" :        在此目录下搜索包含findString 的所有java文件

       mgrep   "findString"  :   在此目录下搜索包含findString 的所有mk文件

      resgrep  "findString" :       在此目录下搜索包含findString的所有资源(xml)文件

     mangrep  "findString" :      在此目录下搜索包含findString的所有AndroidManifest.xml 文件

3.  lunch命令

        当执行完lunch命令后:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=full_k79v1_64
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a53
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=cortex-a53
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.13.0-41-generic-x86_64-Ubuntu-20.04.3-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RP1A.200720.011
OUT_DIR=out
============================================

我们对这些参数进行解释说明:

lunch结果解释说明
PLATFORM_VERSION_CODENAME=REL表示平台版本的名称
PLATFORM_VERSION=11Android平台的版本号
TARGET_PRODUCT=full_k79v1_64所编译的产品名称
TARGET_BUILD_VARIANT=userdebug  所编译产品的类型
TARGET_BUILD_TYPE=release编译的类型,debug和release
TARGET_ARCH=arm      表示编译目标的CPU架构
TARGET_ARCH_VARIANT=armv8-a表示编译目标的CPU架构版本
TARGET_CPU_VARIANT=cortex-a53表示编译目标的CPU代号
HOST_ARCH=x86_64    表示编译平台的架构
HOST_2ND_ARCH=x86表示编译平台的第二CPU架构
HOST_OS=linux      表示编译平台的操作系统
HOST_OS_EXTRA=Linux-5.13.0-41-generic-x86_64-Ubuntu-20.04.3-LTS编译系统之外的额外信息
HOST_CROSS_OS=windows

HOST_CROSS_ARCH=x86

HOST_CROSS_2ND_ARCH=x86_64

HOST_BUILD_TYPE=release

编译类型
BUILD_ID=RP1A.200720.011BUILD_ID会出现在版本信息中,可以利用
OUT_DIR=out        编译结果输出的路径

  • 4
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值