当前位置:网站首页>Andorid source build/envsetup.sh 该知道的细节
Andorid source build/envsetup.sh 该知道的细节
2022-06-29 23:50:00 【broadview_java】
1. 前言
在编译Android源码时,开始一定会初始化系统环境变量,两条熟悉的命令:
source build/envsetup.sh
lunch xxx
那这样子初始化,有什么作用呢,初始化环境变量后有哪些快捷开发指令可以用呢? 我们来总结一下。
2. envsetup.sh命令
执行 source build/envsetup.sh命令时,这里的envsetup.sh被link到了 build/make/envsetup.sh文件

此时在终端输入 hmm 命令,如下:
[email protected]:~/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的中文翻译为“根”,大致意思就是回到工程代码的根目录,比如你在某个模块下面,想回到根目录,执行此命令:
[email protected]:~/project/mount/cts/android11$ cd frameworks/base/packages/services/
[email protected]:~/project/mount/cts/android11/frameworks/base/packages/services$ croot
[email protected]:/mnt/mount/cts/android11$
2.2 gomod <module>
直接跳转到某个子模块,这个很方便切换查看模块代码
[email protected]:/mnt/mount/cts/android11$ gomod Settings
[email protected]:/mnt/mount/cts/android11/packages/apps/Settings$2.3 pathmod <module>
显示当前模块的路径 和 pwd 命令同样的意思
[email protected]:/mnt/mount/cts/android11/packages/apps/Settings$ pathmod Settings
/mnt/mount/cts/android11/packages/apps/Settings2.4 m mm mmm
编译整个工程,编译某个模块常用命令
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=11 | Android平台的版本号 |
| 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.011 | BUILD_ID会出现在版本信息中,可以利用 |
| OUT_DIR=out | 编译结果输出的路径 |
边栏推荐
- Fund information disclosure
- Matlab exercises -- program control process exercise
- 云服务器的安全设置常识
- Shell operator
- 剑指 Offer 14- II. 剪绳子 II
- Unity about failure (delay) of destroy and ondestroy
- Create an API rapid development platform, awesome!
- Simple understanding of B tree and b+ tree
- [wechat applet] understand the basic composition of the applet project
- @Scheduled annotation pit, I stepped on it for you
猜你喜欢

koa2学习和使用
![[wechat applet] understand the basic composition of the applet project](/img/71/98894fbb9cda4facfd2b83c8ec8f9a.png)
[wechat applet] understand the basic composition of the applet project

云服务器的安全设置常识

Yunhe enmo Guoqiang, identifiez - le, saisissez - le, avant l'ébullition de la base de données nationale

FPGA Development (1) -- serial port communication

Sword finger offer 14- I. cut rope

这个简单的小功能,半年为我们产研团队省下213个小时

Sword finger offer 14- ii Cutting rope II

剑指 Offer 15. 二进制中1的个数

FPGA开发(1)——串口通信
随机推荐
[LeetCode] 只出现一次的数字【136】
What is online account opening? In addition, is it safe to open a mobile account?
Solr基础操作4
Teach you step by step to install webwind notes on edge browser
简单理解B树和B+树
MetaQ集群安裝測試
Leetcode(680)——验证回文字符串 Ⅱ
How about counting Berry Pie 4? What are the possible ways to play?
Divisor
深度学习的历史
打造一个 API 快速开发平台,牛逼!
LC:有效的数独 + 旋转图像
数莓派 4怎么样?可能的玩法有哪些?
Unity about failure (delay) of destroy and ondestroy
Leetcode (680) -- verifying palindrome string II
@Scheduled annotation pit, I stepped on it for you
Head pressing Amway good-looking and practical dispensing machine SolidWorks model material here
Xutils3 transfer set
Profit distribution and taxation of funds
架构实战营模块5作业