apktool
Decode and encode Android APK files
TLDR
Decode an APK file
Build an APK file from a directory
Install and store a framework
SYNOPSIS
apktool [global_options] <command> [command_options] [arguments]
Common Commands:
apktool d [options] <file.apk> (Decode an APK)
apktool b [options] <decoded_folder> (Build an APK from a decoded folder)
apktool if <framework.apk> (Install a framework file)
PARAMETERS
d, decode
Decodes an APK file, extracting resources and Smali source code into a specified directory.
b, build
Rebuilds an APK from a previously decoded project directory, generating a new APK file.
if, install-framework
Installs an Android framework file (e.g., from a specific Android version or manufacturer) for better decoding/building compatibility.
-f, --force
(Decode/Build) When decoding, forces deletion of the existing output directory. When building, forces rebuilding all files, skipping change detection.
-o, --output <path>
(Decode/Build) Specifies the output directory for decoding or the output APK file name for building.
-r, --no-res
(Decode) Prevents decoding of resources (XML layouts, strings, images, etc.), focusing only on source code extraction.
-s, --no-src
(Decode) Prevents decoding of source code (Smali), only extracting resources.
-d, --debug
(Build) Sets the 'android:debuggable' flag to 'true' in the AndroidManifest.xml when rebuilding the application.
--use-aapt2
(Decode/Build) Instructs apktool to utilize aapt2 for resource processing, if available, which can improve compatibility and speed with newer Android versions.
DESCRIPTION
apktool is a powerful open-source command-line utility used for reverse engineering Android applications. It can decode resources to their nearly original form and rebuild modified APKs. This makes it invaluable for security researchers, Android developers, and enthusiasts who need to analyze, modify, or debug Android applications without access to their original source code.
It handles various aspects of APK structure, including resources (XML layouts, strings, images), Smali code (disassembled DEX bytecode), and the AndroidManifest.xml file. apktool facilitates tasks such as localization, adding features, debugging, and identifying vulnerabilities by allowing users to inspect and manipulate an app's internal workings. It aims to be as compatible as possible with different Android versions and device manufacturers by managing framework files.
CAVEATS
- A Java Runtime Environment (JRE) is required for apktool to function.
- Rebuilt APKs are unsigned and must be signed with a tool like apksigner or jarsigner before they can be installed on an Android device.
- Decoding heavily obfuscated applications can be challenging, as the resulting Smali code might be difficult to understand or modify.
- Accuracy of decoding and successful rebuilding can depend on the presence of appropriate framework files installed via apktool if.
<I>TYPICAL WORKFLOW</I>
A common workflow for using apktool involves:
1. Decoding an APK: `apktool d original.apk`
2. Modifying the extracted Smali code or resource files (XML, images) within the generated directory.
3. Rebuilding the application: `apktool b decoded_folder`
4. Signing the newly built APK using external tools like `apksigner` or `jarsigner` before it can be installed on an Android device.
<I>SMALI CODE</I>
When decoding, apktool disassembles the Dalvik/ART bytecode (found in DEX files) into a human-readable assembly-like language called Smali. Modifications to an application's core logic are typically made by editing these Smali files, which are then reassembled back into DEX bytecode during the build process.
<I>FRAMEWORK FILES</I>
For proper decoding and rebuilding, especially for system applications or apps targeting specific Android versions/manufacturers, apktool often requires 'framework' files. These files contain compiled resource definitions that apktool uses to correctly interpret and reconstruct resources. They can be installed using the `apktool if` command, referencing a framework APK (e.g., from a device's system directory or an SDK).
HISTORY
apktool was created by Brut.all as an open-source project. Its development began in the early days of Android, driven by the need for developers and security researchers to inspect and modify compiled Android applications. It quickly became a de-facto standard tool in the Android reverse engineering community due to its reliability and comprehensive features for both decoding and rebuilding APKs, a functionality often missing in other tools that only focused on one aspect. Its continuous development ensures compatibility with newer Android versions and build tools like aapt2.