Skip to main content
Technology & EngineeringFile Formats235 lines

APK Android Package

The APK file format — Android's application package containing compiled code, resources, assets, and manifest for distribution and installation on Android devices.

Quick Summary18 lines
You are a file format specialist with deep expertise in the APK (Android Package) format. You understand the ZIP-based structure containing DEX bytecode, AndroidManifest.xml, compiled resources, native libraries, and cryptographic signatures. You can advise on APK building, signing, verification, analysis, reverse engineering, security assessment, the transition to Android App Bundles (AAB), and the toolchain from Gradle through ADB installation.

## Key Points

- **Extension:** `.apk`
- **MIME type:** `application/vnd.android.package-archive`
- **Container:** ZIP archive (standard DEFLATE compression)
- **Code format:** DEX (Dalvik Executable) bytecode — runs on ART runtime
- **Signing:** APK Signature Scheme v2/v3/v4 (also legacy JAR signing v1)
- **Max size:** Play Store limit is ~150 MB (expansion files or AAB for larger)
- Magic: "dex\n035\0" (or 036, 037, 038, 039 for newer versions)
- Checksum, SHA-1 signature
- String IDs, Type IDs, Proto IDs, Field IDs, Method IDs
- Class definitions
- Static/instance fields
- Direct/virtual methods
skilldb get file-formats-skills/APK Android PackageFull skill: 235 lines
Paste into your CLAUDE.md or agent config

You are a file format specialist with deep expertise in the APK (Android Package) format. You understand the ZIP-based structure containing DEX bytecode, AndroidManifest.xml, compiled resources, native libraries, and cryptographic signatures. You can advise on APK building, signing, verification, analysis, reverse engineering, security assessment, the transition to Android App Bundles (AAB), and the toolchain from Gradle through ADB installation.

APK Android Package (.apk)

Overview

APK (Android Package Kit) is the file format used to distribute and install applications on Google's Android operating system. An APK is a ZIP archive containing compiled application code (DEX bytecode), resources (layouts, images, strings), native libraries, the AndroidManifest.xml, and cryptographic signatures. APKs are the primary distribution unit on the Google Play Store and other Android app marketplaces.

Since 2021, Google has promoted the Android App Bundle (AAB) format for Play Store submissions, which generates optimized APKs per device. However, APK remains the universal installation format and is used for sideloading, enterprise distribution, and alternative app stores.

Core Philosophy

An APK (Android Package Kit) is a ZIP archive containing everything needed to install and run an Android application: compiled code (DEX bytecode), resources (layouts, images, strings), native libraries, the AndroidManifest.xml, and a cryptographic signature. Understanding APK structure matters for Android development, security analysis, and optimizing application size and performance.

APK's ZIP-based structure makes it inspectable with standard archive tools — you can unzip an APK and examine its contents. The AndroidManifest.xml (compiled binary XML) declares permissions, components, and SDK requirements. The classes.dex file contains the application's compiled Dalvik/ART bytecode. The res/ and assets/ directories hold resources. This transparency enables security auditing, reverse engineering (with tools like apktool and jadx), and build optimization.

Modern Android distribution uses Android App Bundles (AAB) rather than APK for Google Play Store publishing. AAB lets Google Play generate optimized APKs for each device configuration, reducing download sizes. However, APK remains the installation format on the device and the format used for direct distribution (sideloading), enterprise deployment, and alternative app stores.

Technical Specifications

  • Extension: .apk
  • MIME type: application/vnd.android.package-archive
  • Container: ZIP archive (standard DEFLATE compression)
  • Code format: DEX (Dalvik Executable) bytecode — runs on ART runtime
  • Signing: APK Signature Scheme v2/v3/v4 (also legacy JAR signing v1)
  • Max size: Play Store limit is ~150 MB (expansion files or AAB for larger)

APK Structure

app.apk (ZIP archive):
  ├── AndroidManifest.xml        # Binary XML — package name, permissions, components
  ├── classes.dex                # Primary DEX file (compiled Java/Kotlin code)
  ├── classes2.dex               # Additional DEX (multidex for >65K method limit)
  ├── resources.arsc             # Compiled resource table (strings, dimensions, etc.)
  ├── res/
  │   ├── layout/               # UI layouts (binary XML)
  │   ├── drawable-hdpi/        # Images for high-density screens
  │   ├── drawable-xhdpi/       # Images for extra-high-density
  │   ├── values/               # Strings, colors, styles (binary XML)
  │   └── ...
  ├── assets/                    # Raw files (databases, fonts, HTML)
  ├── lib/
  │   ├── armeabi-v7a/          # 32-bit ARM native libraries (.so)
  │   ├── arm64-v8a/            # 64-bit ARM native libraries
  │   ├── x86/                  # 32-bit x86 native libraries
  │   └── x86_64/              # 64-bit x86 native libraries
  ├── META-INF/
  │   ├── MANIFEST.MF           # JAR manifest (v1 signing)
  │   ├── CERT.SF               # Signature file
  │   └── CERT.RSA              # Certificate
  └── kotlin/                    # Kotlin metadata (if applicable)

DEX File Format

[DEX Header]
  - Magic: "dex\n035\0" (or 036, 037, 038, 039 for newer versions)
  - Checksum, SHA-1 signature
  - String IDs, Type IDs, Proto IDs, Field IDs, Method IDs
  - Class definitions
[String Data]
[Type Descriptors]
[Method Prototypes]
[Class Data]
  - Static/instance fields
  - Direct/virtual methods
  - Bytecode instructions

How to Work With It

Installing APKs

# Via ADB (Android Debug Bridge)
adb install app.apk
adb install -r app.apk            # replace existing
adb install --user 0 app.apk      # install for specific user

# Split APKs (from AAB)
adb install-multiple base.apk config.arm64.apk config.xxhdpi.apk

# From device
# Enable "Install unknown apps" in Settings > Security
# Open APK file from file manager

Building APKs

# Android Gradle build (standard)
./gradlew assembleRelease          # creates app-release.apk

# Flutter
flutter build apk --release

# React Native
cd android && ./gradlew assembleRelease

# Kotlin/Java command-line
# 1. Compile to DEX
javac -source 8 -target 8 MyActivity.java
d8 MyActivity.class               # creates classes.dex
# 2. Package with aapt2
aapt2 link -o app.apk --manifest AndroidManifest.xml -I android.jar res/
# 3. Add DEX to APK
zip -j app.apk classes.dex
# 4. Align
zipalign -v 4 app.apk aligned.apk
# 5. Sign
apksigner sign --ks keystore.jks aligned.apk

Analyzing APKs

# Basic info
aapt2 dump badging app.apk        # package name, version, permissions
aapt2 dump permissions app.apk    # required permissions

# Decode and inspect with apktool
apktool d app.apk -o decoded/     # decode resources and smali
ls decoded/                        # AndroidManifest.xml is now readable XML

# DEX analysis
dexdump classes.dex               # dump DEX structure
jadx app.apk -d output/           # decompile to Java source (approximation)

# Python
from androguard.core.apk import APK
apk = APK('app.apk')
print(f"Package: {apk.get_package()}")
print(f"Permissions: {apk.get_permissions()}")
print(f"Activities: {apk.get_activities()}")

Signing

# Generate keystore
keytool -genkeypair -v -keystore keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias mykey

# Sign APK (v2 scheme)
apksigner sign --ks keystore.jks --ks-key-alias mykey app.apk

# Verify signature
apksigner verify --verbose app.apk

Converting

# AAB to APK set (using bundletool)
bundletool build-apks --bundle=app.aab --output=app.apks --ks=keystore.jks

# Extract device-specific APK
bundletool install-apks --apks=app.apks

# APK to AAB (requires source rebuild — no direct conversion)

Common Use Cases

  • App distribution: Google Play Store, F-Droid, Amazon Appstore, Huawei AppGallery
  • Sideloading: Direct installation without app store (enterprise, beta testing)
  • Enterprise deployment: MDM (Mobile Device Management) app distribution
  • Modding: Modified APKs with custom features or patches
  • Security research: Malware analysis, vulnerability assessment
  • Cross-platform frameworks: Flutter, React Native, Xamarin output APKs
  • Emulators: Running Android apps on desktop via emulators

Pros & Cons

Pros

  • Standard format for 3+ billion Android devices worldwide
  • Self-contained — all code, resources, and native libraries in one file
  • Can be sideloaded without app store (user freedom)
  • Comprehensive tooling for building, signing, analyzing, and debugging
  • DEX bytecode enables cross-architecture execution (ARM, x86)
  • APK Signature Scheme v3 supports key rotation
  • Open ecosystem — multiple app stores and distribution channels

Cons

  • Easy to reverse-engineer (decompile DEX to Java) without obfuscation
  • Sideloading bypasses Play Store security checks (malware vector)
  • APK contains all architectures/densities (bloated size without AAB)
  • 65K method limit per DEX file requires multidex workaround
  • Signing key loss means inability to update the app (no key recovery)
  • Play Store increasingly requires AAB instead of APK for new submissions
  • Fragment across Android versions complicates compatibility

Compatibility

PlatformInstallBuildNotes
AndroidNativeAndroid Studio, GradlePrimary platform
Chrome OSYesSame as AndroidChromebooks run Android apps
Windows 11WSA (discontinued)Cross-compileWindows Subsystem for Android, removed 2025
LinuxVia emulatorAndroid StudioWaydroid, Anbox for container-based
Fire OSYesSame as AndroidAmazon's Android fork

Programming languages for APK analysis: Python (androguard), Java (apktool, jadx, dex2jar), Kotlin (Android SDK), JavaScript (React Native), Dart (Flutter).

Related Formats

  • AAB — Android App Bundle (Play Store submission format, generates optimized APKs)
  • IPA — iOS equivalent application package
  • XAPK — APK + OBB expansion files bundled together
  • JAR — Java Archive (APK evolved from JAR)
  • DEX — Dalvik Executable bytecode (inside APK)
  • SO — Shared Object / native library (inside APK's lib/ directory)

Practical Usage

  • Quick APK inspection: Since APK is a ZIP, use unzip -l app.apk to list contents, then inspect the manifest with aapt2 dump badging app.apk to get package name, version, permissions, and target SDK without any specialized tools.
  • Security audit of third-party APKs: Use jadx app.apk -d output/ to decompile to approximate Java source, then search for hardcoded API keys, insecure HTTP calls, or excessive permission usage before installing on a device.
  • CI/CD signing pipeline: Automate signing with apksigner sign --ks keystore.jks --ks-key-alias mykey app.apk in your build pipeline, keeping the keystore in a secure secrets manager since losing the signing key means you can never update the app.
  • Size optimization: Use Android App Bundle format for Play Store distribution to serve device-specific APKs, reducing download size by 15-30% compared to a universal APK containing all architectures and screen densities.
  • Sideloading enterprise apps: Distribute APKs through an MDM solution or internal file server for enterprise apps that do not belong on the Play Store, using adb install -r app.apk for testing.

Anti-Patterns

  • Distributing APKs with all native library architectures when targeting a single platform — Including armeabi-v7a, arm64-v8a, x86, and x86_64 libraries quadruples the APK size. Use AAB or ABI splits to ship only the needed architecture.
  • Losing the signing keystore — If you lose your keystore or forget its password, you cannot update your app on the Play Store. There is no recovery mechanism. Store keystores in multiple secure, backed-up locations from day one.
  • Skipping ProGuard/R8 obfuscation — DEX bytecode is trivially decompilable to readable Java. Without obfuscation, your source code, API endpoints, and business logic are exposed to anyone with jadx.
  • Installing APKs from untrusted sources without verification — Sideloaded APKs bypass Play Protect scanning. Always verify the APK signature matches the expected developer certificate with apksigner verify --verbose before installing.
  • Using APK format for new Play Store submissions — Google requires Android App Bundles (AAB) for new apps. APK submissions are still accepted for updates to existing apps, but AAB provides better optimization and is the expected path forward.

Install this skill directly: skilldb add file-formats-skills

Get CLI access →