指令列工具
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android SDK 是由開發應用程式所需的多種套件組成。
此頁面列出了最重要的指令列工具 (可供使用,且按照提供這些工具的套件整理)。
您可以使用 Android Studio 的 SDK Manager 或 sdkmanager
指令列工具安裝及更新每個套件。
所有套件都會下載到您的 Android SDK 目錄中,您可以按照下列步驟找到該目標:
- 在 Android Studio 中,依序按一下「File」(檔案) >「Project Architecture」(專案結構)。
- 選取左側窗格中的「SDK Location」(SDK 位置)。路徑會顯示在「Android SDK location」下方。
設定環境變數
建議您在使用指令列時,為 ANDROID_HOME
設定環境變數。此外,請將指令搜尋路徑設為加入 ANDROID_HOME/tools
、ANDROID_HOME/tools/bin
和 ANDROID_HOME/platform-tools
,以找出最常見的工具。相關步驟會因作業系統而異,但請參閱「如何設定環境變數」一文,瞭解一般指南。
位於:android_sdk/cmdline-tools/version/bin/
注意:Android SDK 指令列工具套件 (位於 cmdline-tools
) 會取代位於 tools
的 SDK 工具套件。透過新套件,您可以選取要安裝的指令列工具版本,也可以一次安裝多個版本。如果使用舊套件,只能安裝最新版本的工具。因此,借助新套件,您可以在發布新版本時依附指令列工具的特定版本,而不必破壞程式碼。如需已淘汰 SDK 工具套件的相關資訊,請參閱「SDK 工具版本資訊」。
如果您尚未使用 Android Studio,可以在這裡下載指令列工具套件。
apkanalyzer
- 在建構程序完成後,提供 APK 可組成項的深入分析。
avdmanager
- 可讓您透過指令列建立及管理 Android 虛擬裝置 (AVD)。
lint
- 掃描程式碼,協助您找出並修正程式碼的結構品質問題。
retrace
- 針對由 R8 編譯的應用程式,
retrace
會將經過模糊處理的堆疊追蹤解碼,該堆疊追蹤會對應回原本的原始碼。
sdkmanager
- 可讓您查看、安裝、更新及解除安裝 Android SDK 的套件
位於:android_sdk/build-tools/version/
詳情請參閱「SDK 建構工具版本資訊」。
必須使用這個套件才能建構 Android 應用程式。這個套件中的大部分工具都是由建構工具叫用,並非供您使用。不過,下列指令列工具可能相當實用:
AAPT2
- 可以剖析 Android 資源、為資源建立索引,並將其編譯為針對 Android 平台最佳化的二進位檔格式,然後將編譯過的資源封裝為單一輸出內容。
apksigner
- 簽署 APK,並檢查 APK 簽名能否在特定 APK 支援的所有平台版本上成功通過驗證。
zipalign
- 確保所有未壓縮的資料均以檔案開頭做為特定對齊位置,對 APK 檔案進行最佳化處理。
附註:您可以擁有多個版本的建構工具,為不同的 Android 版本建構應用程式。
位於:android_sdk/platform-tools/
詳情請參閱「SDK 平台工具版本資訊」。
在 Android 平台推出每個新版本時,這些工具都會執行相應地更新,以支援新功能並修正問題或改善工具,而且每次更新也會與舊版平台版本回溯相容。
除了從 SDK Manager 下載之外,您也可以在這裡下載 SDK 平台工具。
adb
- Android Debug Bridge (ADB) 是一種多功能工具,您可以利用此工具管理模擬器執行個體或 Android 裝置的狀態,也可以用來在裝置上安裝 APK。
etc1tool
- 一種指令列公用程式,您可以使用此程式將 PNG 圖片編碼為 ETC1 壓縮標準,並將 ETC1 壓縮圖片解碼回 PNG。
fastboot
- 使用平台和其他系統映像檔刷新裝置。如需刷新的操作說明,請參閱「Nexus 和 Pixel 裝置的原廠映像檔」。
logcat
- 此工具可透過 ADB 叫用,以便查看應用程式和系統記錄。
位於:android_sdk/emulator/
詳情請參閱「Android Emulator 版本資訊」。
必須有此套件才能使用 Android Emulator。包含的內容如下:
emulator
- 一種基於 QEMU 的裝置模擬工具,您可以利用此工具,在實際的 Android 執行期間偵錯及測試應用程式。
mksdcard
- 協助您建立能與模擬器搭配使用的磁碟映像檔,以模擬具備外部儲存空間卡 (例如 SD 卡) 的情況。
注意:在 25.3.0 之前的版本中,模擬器工具包含在 SDK 工具套件中。
Jetifier
Jetifier 讀取使用支援資料庫類別的程式庫,並輸出使用新版 AndroidX 類別的對等程式庫。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2023-12-02 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2023-12-02 (世界標準時間)。"],[],[],null,["# Command-line tools\n\nThe Android SDK is composed of multiple packages that are required for app development.\nThis page lists the most important command-line tools that are\navailable, organized by the packages in which they're delivered.\n\nYou can install and update each package using\nAndroid Studio's [SDK Manager](/studio/intro/update#sdk-manager)\nor the [`sdkmanager`](/studio/command-line/sdkmanager)\ncommand-line tool.\nAll of the packages are downloaded into your Android SDK directory, which\nyou can locate as follows:\n\n1. In Android Studio, click **File \\\u003e Project Structure**.\n2. Select **SDK Location** in the left pane. The path is shown under **Android SDK location**.\n\n### Set environment variables\n\nWe recommend setting the environment variable for\n[\u003cvar translate=\"no\"\u003eANDROID_HOME\u003c/var\u003e](/studio/command-line/variables#envar) when using\nthe command line. Also, set your command search path to include\n\u003cvar translate=\"no\"\u003eANDROID_HOME/tools\u003c/var\u003e, \u003cvar translate=\"no\"\u003eANDROID_HOME/tools/bin\u003c/var\u003e, and\n\u003cvar translate=\"no\"\u003eANDROID_HOME/platform-tools\u003c/var\u003e to find the most common tools. The steps\nvary depending on your OS, but read\n[How to set environment variables](/studio/command-line/variables#set) for general guidance.\n\nAndroid SDK Command-Line Tools\n------------------------------\n\n\nLocated in: \u003cvar translate=\"no\"\u003eandroid_sdk\u003c/var\u003e`/cmdline-tools/`\u003cvar translate=\"no\"\u003eversion\u003c/var\u003e`/bin/` \n\nNote: The Android SDK Command-Line Tools package, located in\n`cmdline-tools`, replaces the SDK Tools package, located in `tools`. With\nthe new package, you can select the version of the command line tools you want to install,\nand you can install multiple versions at a time. With the old package, you can only install the\nlatest version of the tools. Thus, the new package lets you depend on specific versions of the\ncommand-line tools without having your code break when new versions are released. For information\nabout the deprecated SDK Tools package, see the\n[SDK Tools release notes](/studio/releases/sdk-tools).\n\nIf you are not using Android Studio, you can download the command-line tools package\n[here](/studio#command-tools).\n\n[apkanalyzer](/studio/command-line/apkanalyzer)\n: Provides insight into the composition of your APK after the build process completes.\n\n[avdmanager](/studio/command-line/avdmanager)\n: Lets you create and manage Android Virtual Devices (AVDs)\n from the command line.\n\n[lint](/studio/write/lint#commandline)\n: Scans code to help you identify and correct problems\n with the structural quality of your code.\n\n[`retrace`](/studio/command-line/retrace)\n: For applications compiled by R8, `retrace` decodes an obfuscated stack trace that\n maps back to your original source code.\n\n[sdkmanager](/studio/command-line/sdkmanager)\n: Lets you view, install, update, and uninstall packages for the Android SDK\n\nAndroid SDK Build Tools\n-----------------------\n\n\nLocated in: \u003cvar translate=\"no\"\u003eandroid_sdk\u003c/var\u003e`/build-tools/`\u003cvar translate=\"no\"\u003eversion\u003c/var\u003e`/` \n\nSee [SDK Build Tools release notes](/studio/releases/build-tools) for more\ninformation.\n\nThis package is required to build Android apps. Most of the tools in this package are\ninvoked by the build tools and not intended for you. However, the following\ncommand-line tools might be useful:\n\n[`AAPT2`](/studio/command-line/aapt2)\n: Parses, indexes, and compiles Android resources into a binary format that\n is optimized for the Android platform and packages the compiled resources\n into a single output.\n\n[`apksigner`](/studio/command-line/apksigner)\n: Signs APKs and checks whether APK signatures will be verified\n successfully on all platform versions that a given APK supports.\n\n[`zipalign`](/studio/command-line/zipalign)\n: Optimizes APK files by ensuring that all uncompressed data starts with\n a particular alignment relative to the start of the file.\n\n**Note:** You can have multiple versions of the build tools\nto build your app for different Android versions.\n\nAndroid SDK Platform Tools\n--------------------------\n\n\nLocated in: \u003cvar translate=\"no\"\u003eandroid_sdk\u003c/var\u003e`/platform-tools/` \n\nSee [SDK Platform Tools release notes](/studio/releases/platform-tools) for more\ninformation.\n\nThese tools are updated for every new version of the Android platform to support new features\nand fix or improve the tools, and each update\nis backward compatible with earlier platform versions.\n\nIn addition to downloading from the SDK Manager, you can download the SDK Platform Tools\n[here](/studio/releases/platform-tools#downloads.html).\n\n[`adb`](/studio/command-line/adb)\n: Android Debug Bridge (adb) is a versatile tool that lets you manage the state of an\n emulator instance or Android-powered device. You can also use it to install an APK on a\n device.\n\n[`etc1tool`](/studio/command-line/etc1tool)\n: A command-line utility that lets you encode PNG images to the ETC1\n compression standard and decode ETC1 compressed images back to PNG.\n\n`fastboot`\n: Flashes a device with platform and other system images. For flashing instructions,\n see [Factory Images for Nexus and\n Pixel Devices](https://developers.google.com/android/images).\n\n[`logcat`](/studio/command-line/logcat)\n: Invoked by adb to view app and system logs.\n\nAndroid Emulator\n----------------\n\n\nLocated in: \u003cvar translate=\"no\"\u003eandroid_sdk\u003c/var\u003e`/emulator/` \n\nSee [Android Emulator release notes](/studio/releases/emulator) for more\ninformation.\n\nThis package is required to use the Android Emulator. It includes the following:\n\n[emulator](/studio/run/emulator-commandline)\n: A QEMU-based device-emulation tool that you can use to debug and test\n your applications in an actual Android run-time environment.\n\n[mksdcard](/studio/command-line/mksdcard)\n: Helps you create a disk image that you can use with the emulator\n to simulate the presence of an external storage card, such as an SD card.\n\n**Note:** Prior to revision 25.3.0, the emulator tools were included with the\nSDK Tools package.\n\nJetifier\n--------\n\n[Jetifier](/studio/command-line/jetifier) reads a library that uses\nSupport Library classes and outputs an equivalent library that uses the newer\nAndroidX classes."]]