在系統源碼中發現的一些命令和快捷方式。我們在編譯源碼之前執行的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