aapt
Inspect, package, and manage Android archive files
TLDR
List files contained in an APK archive
Display an app's metadata (version, permissions, etc.)
Create a new APK archive with files from the specified directory
SYNOPSIS
aapt <command> [options] [arguments]
Common command usage examples:
aapt package [options] -M <AndroidManifest.xml> -I <android.jar> -S <resource_dir> -F <output.apk>
aapt dump <subcommand> <file.apk>
PARAMETERS
package
Subcommand: Creates or updates an APK file, processing resources and assets.
dump
Subcommand: Dumps detailed information from an APK file, specified by a sub-option (e.g., badging, resources).
list
Subcommand: Lists the contents of an APK file, similar to zip -l.
add
Subcommand: Adds a new file to an existing APK archive.
remove
Subcommand: Removes a file from an existing APK archive.
crunch
Subcommand: Optimizes (crunches) PNG files, typically reducing file size. This is usually done automatically during packaging.
version
Subcommand: Prints the aapt version number.
-S <dir>
Option (for package): Specifies the path to a resource directory. Can be used multiple times.
-A <dir>
Option (for package): Specifies the path to an assets directory. Can be used multiple times.
-I <file>
Option (for package): Specifies the path to an Android framework JAR file (e.g., android.jar) to include for compilation.
-M <file>
Option (for package): Specifies the path to the AndroidManifest.xml file.
-F <file>
Option (for package): Specifies the output APK file name.
-J <dir>
Option (for package): Specifies the directory where the R.java file should be generated.
-0 <extension>
Option (for package): Specifies file extensions that should not be compressed in the APK (e.g., .png, .jpg).
--no-compress
Option (for package): Prevents compression of any files within the APK.
badging
Sub-option (for dump): Dumps human-readable information about the APK, including application label, icon, permissions, and activities.
permissions
Sub-option (for dump): Dumps the permissions declared in the APK's manifest.
xmltree <file>
Sub-option (for dump): Dumps a binary XML file (e.g., AndroidManifest.xml) as a human-readable XML tree structure.
DESCRIPTION
aapt, the Android Asset Packaging Tool, is a command-line utility integral to the Android SDK's build process. It compiles and packages application resources (such as layouts, strings, and images) and compiled code into an Android application package (.apk) file. This tool is responsible for tasks like parsing AndroidManifest.xml, compiling resource directories, and generating the binary resources.arsc file that points to compiled resources. Beyond packaging, aapt also provides functionalities to inspect existing APKs, allowing users to dump various details including package information, activities, permissions, and resource tables. While typically invoked by higher-level build systems like Gradle, it can be used directly for specific development and debugging purposes. It plays a crucial role in bridging raw application assets with the final distributable Android package.
CAVEATS
aapt has largely been superseded by aapt2, which offers improved performance, better error reporting, and supports incremental compilation. While still present in the Android SDK Build-Tools, modern Android development typically relies on Gradle, which internally uses aapt2. Direct usage of aapt is generally for specific inspection or legacy build scenarios.
AAPT VS. AAPT2
The primary difference between aapt and aapt2 lies in their architecture and performance. aapt2 splits the packaging process into two distinct steps: compile and link. This separation allows for incremental compilation, meaning only modified resources need to be recompiled, significantly speeding up build times. aapt2 also provides more detailed error reporting and better support for modern Android features and resource types, making it the preferred tool for current Android development.
HISTORY
aapt has been a foundational component of the Android SDK since its inception, serving as the primary tool for packaging application resources and assets into APKs. Its capabilities were essential for the entire Android build pipeline. As Android development evolved and projects grew in complexity, the need for faster, more robust, and incrementally compilable resource processing became evident. This led to the development and introduction of aapt2 (Android Asset Packaging Tool 2), which became the default resource processor for the Android Gradle Plugin starting with AGP 3.0.0. While aapt remains available, aapt2 is now the recommended and actively developed tool for Android resource compilation and packaging.