AOSP Framework开发的一些超方便的快捷命令
在系统源码中发现的一些命令和快捷方式。我们在编译源码之前执行的source build/envsetup.sh,通过cat build/envsetup.sh发现如下命令
- lunch: lunch <product_name>-<build_variant>Selects <product_name> as the product to build, and <build_variant> as the variant tobuild, and stores those selections in the environment to be read by subsequentinvocations of 'm' etc.
- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]Sets up the build environment for building unbundled apps (APKs).
- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]Sets up the build environment for building unbundled modules (APEXes).
- croot: Changes directory to the top of the tree, or a subdirectory thereof.
- m: Makes from the top of the tree.
- mm: Builds and installs all of the modules in the current directory, and theirdependencies.
- mmm: Builds and installs all of the modules in the supplied directories, and theirdependencies.To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Same as 'mm'
- mmma: Same as 'mmm'
- 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.
- gogrep: Greps on all local Go files.
- jgrep: Greps on all local Java files.
- ktgrep: Greps on all local Kotlin files.
- resgrep: Greps on all local res/*.xml files.
- mangrep: Greps on all local AndroidManifest.xml files.
- mgrep: Greps on all local Makefiles and *.bp files.
- owngrep: Greps on all local OWNERS files.
- rsgrep: Greps on all local Rust 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.
- outmod: Gets the location of a module's installed outputs with a certain extension.
- dirmods: Gets the modules defined in a given directory.
- installmod: Adb installs a module's built APK.
- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
1. lunch
lunch <product_name>-<build_variant>
功能:选择要构建的产品和构建变体
参数:
<product_name>:产品名称(如 aosp_arm、sdk_phone_x86)
<build_variant>:构建类型(eng、userdebug、user)
作用:设置环境变量,配置后续构建命令
2. tapas
tapas [ …] [arm|x86|arm64|x86_64] [eng|userdebug|user]
功能:设置构建独立应用(APK)的环境
典型用例:开发特定应用而不构建整个系统
示例:tapas Settings arm64 eng仅构建 Settings 应用
3. banchan
banchan [ …] [arm|x86|arm64|x86_64] [eng|userdebug|user]
功能:设置构建独立模块(APEX)的环境
新增功能:用于模块化开发(Android 10+)
示例:banchan com.android.apex.test arm64 eng
4. croot
功能:快速回到源码树根目录
使用场景:在深层目录中快速返回顶层
等效命令:cd $ANDROID_BUILD_TOP
构建命令
5. m
功能:从源码树根目录开始完整构建
等效命令:make -j$(nproc)
优化:自动检测 CPU 核心数并行构建
6. mm
功能:构建当前目录下的模块及其依赖
特点:不构建整个系统,只构建相关模块
使用场景:快速迭代开发单个模块
7. mmm
mmm <目录1> [<目录2> …]
功能:构建指定目录下的模块
高级用法:mmm dir/:target1,target2指定构建目标
示例:mmm packages/apps/Settings
8. mma
功能:与 mm相同,构建当前目录模块
9. mmma
功能:与 mmm相同,构建指定目录模块
10. provision
provision [fastboot选项]
功能:刷写设备所有必需分区
特点:封装了 fastboot 命令,简化刷机流程
示例:provision -w擦除用户数据
代码搜索工具
11. cgrep
搜索范围:所有 C/C++ 文件(*.c, *.cpp, *.h)
示例:cgrep "main"查找所有 main 函数
12. ggrep
搜索范围:所有 Gradle 文件(*.gradle)
用途:查找构建配置相关代码
13. gogrep
搜索范围:所有 Go 文件(*.go)
新增功能:支持 Go 语言开发(如 Fuchsia 相关)
14. jgrep
搜索范围:所有 Java 文件(*.java)
最常用:Java 代码搜索
15. ktgrep
搜索范围:所有 Kotlin 文件(*.kt)
新增功能:支持 Kotlin 代码搜索
16. resgrep
搜索范围:所有资源 XML 文件(res/*.xml)
用途:查找资源定义
17. mangrep
搜索范围:所有 AndroidManifest.xml 文件
用途:查找应用配置信息
18. mgrep
搜索范围:所有 Makefile 和 *.bp 文件
用途:查找构建系统配置
19. owngrep
搜索范围:所有 OWNERS 文件
用途:查找代码所有者信息
20. rsgrep
搜索范围:所有 Rust 文件(*.rs)
新增功能:支持 Rust 代码搜索
21. sepgrep
搜索范围:所有 sepolicy 文件
用途:查找安全策略配置
22. sgrep
搜索范围:所有源文件
通用搜索:全代码库搜索
导航与模块管理
23. godir
godir <文件名>
功能:跳转到包含指定文件的目录
智能匹配:支持部分文件名匹配
示例:godir AndroidManifest.xml
24. allmod
功能:列出所有可用模块
输出:模块名和路径的列表
25. gomod
gomod <模块名>
功能:跳转到指定模块的目录
示例:gomod Settings
26. pathmod
pathmod <模块名>
功能:获取模块所在目录路径
用途:在脚本中使用模块路径
27. outmod
outmod <模块名> [扩展名]
功能:获取模块输出文件路径
示例:outmod Settings .apk获取 Settings APK 路径
28. dirmods
dirmods <目录>
功能:列出指定目录定义的所有模块
用途:查看目录中的可构建目标
29. installmod
installmod <模块名>
功能:通过 adb 安装模块构建的 APK
自动化:构建 + 安装一步完成
示例:installmod Settings