TExcelTAD
Home › Mobile Build Pipelines: Gradle/AGP, Xcode, SwiftPM & Fastlane › Inspecting APKs: aapt2, apkanalyzer & unzip

Inspecting APKs: aapt2, apkanalyzer & unzip

An APK is a zip file with a known layout. Being able to open one and answer "what's in here?" without Android Studio is a core build-engineering skill: it's how you debug a store rejection, a size regression or a missing resource on CI.

text
app-release.apk
├── AndroidManifest.xml        binary XML (the merged manifest)
├── classes.dex                code (classes2.dex … for large apps)
├── resources.arsc             compiled resource table
├── res/…                      compiled XML, images
├── lib/<abi>/*.so             native libraries
├── assets/…                   raw files
└── META-INF/…                 v1 signature files, metadata
     (+ the v2/v3 APK Signing Block, which isn't a zip entry at all)

The three tools

Tool From Best for
unzip -l any system file list and sizes
aapt2 dump badging / permissions / resources / xmltree build-tools the manifest and resource table, decoded
apkanalyzer command-line tools summaries, sizes, dex contents, comparing two APKs
bash · try it yourself
mkdir -p hello/app/src/main/java/com/example/hello hello/app/src/main/res/values && cd hello
cat > settings.gradle.kts <<'KTS'
pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } }
dependencyResolutionManagement { repositories { google(); mavenCentral() } }
rootProject.name = "hello"
include(":app")
KTS
echo 'plugins { id("com.android.application") version "9.4.1" apply false }' > build.gradle.kts
cat > app/src/main/AndroidManifest.xml <<'XML'
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="@string/app_name">
        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
XML
echo '<resources><string name="app_name">Hello</string></resources>' > app/src/main/res/values/strings.xml
cat > app/src/main/java/com/example/hello/MainActivity.java <<'JAVA'
package com.example.hello;

public class MainActivity extends android.app.Activity {
    @Override protected void onCreate(android.os.Bundle state) {
        super.onCreate(state);
        android.widget.TextView view = new android.widget.TextView(this);
        view.setText(R.string.app_name);
        setContentView(view);
    }
}
JAVA
cat > app/build.gradle.kts <<'KTS'
plugins { id("com.android.application") }
android {
    namespace = "com.example.hello"
    compileSdk = 36
    defaultConfig { applicationId = "com.example.hello"; minSdk = 24; targetSdk = 36; versionCode = 21; versionName = "2.1.0" }
    buildTypes { release { isMinifyEnabled = true; proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt")) } }
}
KTS
gradle wrapper > /dev/null
./gradlew -q assembleRelease
APK=app/build/outputs/apk/release/app-release-unsigned.apk
echo "=== aapt2 dump badging"
aapt2 dump badging $APK | head -6
echo "=== aapt2 dump permissions"
aapt2 dump permissions $APK
echo "=== the binary manifest, decoded"
aapt2 dump xmltree --file AndroidManifest.xml $APK | head -8
echo "=== unzip -l"
unzip -l $APK
=== aapt2 dump badging
package: name='com.example.hello' versionCode='21' versionName='2.1.0' platformBuildVersionName='16' platformBuildVersionCode='36' compileSdkVersion='36' compileSdkVersionCodename='16'
minSdkVersion:'24'
targetSdkVersion:'36'
uses-permission: name='android.permission.INTERNET'
application-label:'Hello'
application: label='Hello' icon=''
=== aapt2 dump permissions
package: com.example.hello
uses-permission: name='android.permission.INTERNET'
=== the binary manifest, decoded
N: android=http://schemas.android.com/apk/res/android (line=2)
  E: manifest (line=2)
    A: http://schemas.android.com/apk/res/android:versionCode(0x0101021b)=21
    A: http://schemas.android.com/apk/res/android:versionName(0x0101021c)="2.1.0" (Raw: "2.1.0")
    A: http://schemas.android.com/apk/res/android:compileSdkVersion(0x01010572)=36
    A: http://schemas.android.com/apk/res/android:compileSdkVersionCodename(0x01010573)="16" (Raw: "16")
    A: package="com.example.hello" (Raw: "com.example.hello")
    A: platformBuildVersionCode=36
=== unzip -l
Archive:  app/build/outputs/apk/release/app-release-unsigned.apk
  Length      Date    Time    Name
---------  ---------- -----   ----
       56  1981-01-01 01:01   META-INF/com/android/build/gradle/app-metadata.properties
       46  1981-01-01 01:01   META-INF/version-control-info.textproto
     1128  1981-01-01 01:01   classes.dex
     1006  1981-01-01 01:01   kotlin/annotation/annotation.kotlin_builtins
     8308  1981-01-01 01:01   kotlin/collections/collections.kotlin_builtins
     2674  1981-01-01 01:01   kotlin/concurrent/atomics/atomics.kotlin_builtins
      137  1981-01-01 01:01   kotlin/coroutines/coroutines.kotlin_builtins
      590  1981-01-01 01:01   kotlin/internal/internal.kotlin_builtins
    29399  1981-01-01 01:01   kotlin/kotlin.kotlin_builtins
     4184  1981-01-01 01:01   kotlin/ranges/ranges.kotlin_builtins
     4827  1981-01-01 01:01   kotlin/reflect/reflect.kotlin_builtins
     2068  1981-01-01 01:01   AndroidManifest.xml
      556  1981-01-01 01:01   resources.arsc
---------                     -------
    54979                     13 files

badging is the quickest way to confirm what a CI job built: package name, version, SDK levels and permissions on a few lines. Its platformBuildVersionName='16' is Android 16, the platform behind compileSdk 36.

Look at the unzip -l list: it has no res/ folder (our only resource is a string, which lives in resources.arsc), a tiny classes.dex, and kotlin/*.kotlin_builtins files. Those come from the Kotlin standard library that AGP 9 adds to every app: R8 removed its classes but not these metadata files, which only Kotlin reflection reads. A Java-only app can exclude them:

kotlin
android {
    packaging { resources { excludes += "**/*.kotlin_builtins" } }
}

apkanalyzer

apkanalyzer answers size questions and can compare two APKs, the core of a size-regression check:

bash · try it yourself
mkdir -p hello/app/src/main/java/com/example/hello && cd hello
cat > settings.gradle.kts <<'KTS'
pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } }
dependencyResolutionManagement { repositories { google(); mavenCentral() } }
rootProject.name = "hello"
include(":app")
KTS
echo 'plugins { id("com.android.application") version "9.4.1" apply false }' > build.gradle.kts
cat > app/src/main/AndroidManifest.xml <<'XML'
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:label="Hello">
        <activity android:name=".MainActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
XML
cat > app/src/main/java/com/example/hello/MainActivity.java <<'JAVA'
package com.example.hello;

public class MainActivity extends android.app.Activity {
    @Override protected void onCreate(android.os.Bundle state) {
        super.onCreate(state);
        android.widget.TextView view = new android.widget.TextView(this);
        view.setText("Hello");
        setContentView(view);
    }
}
JAVA
cat > app/build.gradle.kts <<'KTS'
plugins { id("com.android.application") }
android {
    namespace = "com.example.hello"
    compileSdk = 36
    defaultConfig { applicationId = "com.example.hello"; minSdk = 24; targetSdk = 36; versionCode = 21; versionName = "2.1.0" }
    buildTypes { release { isMinifyEnabled = true; proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt")) } }
}
KTS
gradle wrapper > /dev/null
./gradlew -q assembleRelease
cp app/build/outputs/apk/release/app-release-unsigned.apk before.apk
sed -i 's/^android {/android {\n    packaging { resources { excludes += "**\/*.kotlin_builtins" } }/' app/build.gradle.kts
./gradlew -q assembleRelease
cp app/build/outputs/apk/release/app-release-unsigned.apk after.apk
echo "=== summary (applicationId, versionCode, versionName)"
apkanalyzer apk summary after.apk
echo "=== raw file size: before / after"
apkanalyzer apk file-size before.apk
apkanalyzer apk file-size after.apk
echo "=== compare (old size, new size, difference, path), biggest changes"
apkanalyzer apk compare --different-only before.apk after.apk | sort -t
  

\t' -k3 -n | head -4
echo "=== dex: packages with defined classes"
apkanalyzer dex packages --defined-only after.apk | grep -E '^C'
=== summary (applicationId, versionCode, versionName)
com.example.hello	21	2.1.0
=== raw file size: before / after
15494
2180
=== compare (old size, new size, difference, path), biggest changes
15494	2180	-13314	/
12053	0	-12053	/kotlin/
5342	0	-5342	/kotlin/kotlin.kotlin_builtins
1834	0	-1834	/kotlin/collections/
=== dex: packages with defined classes
C d 2	2	140	com.example.hello.MainActivity

apk compare prints one line per file or folder with the old size, new size and difference: a CI job can fail when the total grows by more than an agreed budget. dex packages lists packages, classes (C), methods (M) and fields (F) with reference counts and sizes; --defined-only hides what's merely referenced from the platform.

Note: apkanalyzer reports raw sizes. What users download from Play is smaller (compressed, and split per device for bundles); use apkanalyzer apk download-size for a compressed estimate and bundletool get-size total for bundles.

Quick answers

Question Command
Which version/package did CI build? aapt2 dump badging x.apk | head -1
Which permissions does it request? aapt2 dump permissions x.apk
Is it debuggable? aapt2 dump badging x.apk | grep application-debuggable
Which strings/resources survived shrinking? aapt2 dump resources x.apk
What does the final manifest say? aapt2 dump xmltree --file AndroidManifest.xml x.apk
Who signed it? apksigner verify --print-certs x.apk
Why did it grow? apkanalyzer apk compare old.apk new.apk
Which classes are in the dex? apkanalyzer dex packages x.apk, or dexdump from build-tools

Test yourself

Why can't you read AndroidManifest.xml inside an APK with unzip -p … | less?

  1. It's encrypted
  2. It's compiled binary XML; use aapt2 dump xmltree (or badging) to decode it
  3. It's not in the APK
  4. It's compressed with zstd

Where do the kotlin/*.kotlin_builtins files in a Java-only app come from?

  1. A bug in aapt2
  2. The kotlin-stdlib that AGP 9 adds; R8 removed its classes but not these metadata resources
  3. The Android platform
  4. The signing step

Which command is the core of an APK size-regression check?

  1. aapt2 dump permissions
  2. apkanalyzer apk compare old.apk new.apk
  3. zipalign -c
  4. keytool -list