Introduction
An .apk file is an Android app
ready to install: its compiled code, its
resources and a manifest describing it, signed by the developer. Apps are now usually
uploaded to Google Play as Android App Bundles (.aab), from which the store
builds APKs for each device, but the installed app is still an APK, and APKs remain the
way to install apps from outside a store.
Structure
An APK is a ZIP archive with a fixed set of entries:
AndroidManifest.xml: the app’s name, components and permissions, in Android’s binary XML format.classes.dex, andclasses2.dexand so on: the app’s code as Dalvik bytecode, which the Android Runtime runs.resources.arsc: the compiled table of strings and other resources.res/andassets/: layouts, images and other files.lib/: native libraries, in a folder per processor type, such aslib/arm64-v8a/.META-INF/: the older, JAR-style signature, when present.
Every entry, the native library folders and the alignment rules are on the
package contents page. The manifest and
other XML files are compiled into a binary chunk format shared with
resources.arsc, described in
binary XML and resources.
Newer signature schemes (version 2 and later) put an APK Signing Block between the last
file entry and the ZIP’s central directory. It covers every other byte of the file, so
changing any of them breaks the signature. Its layout, the v2, v3 and v3.1 signers
and the separate v4 .idsig file are on the
signing block page.
0ZIP entries: manifest, DEX code, resources, librariesvaries…APK Signing Block, for signature scheme v2 and latervaries…central directoryvaries…end of central directory record22 bytes or more
Not described
Known, not yet covered
- Reference: the length rule for UTF-8 strings in the binary XML string pool, the inner layout of the source stamp, the signing-block IDs used by Google Play, the wording of the 16 KB alignment requirement and
app-metadata.properties; see signing and binary XML. - Viewer: there is no viewer for APK files yet.
Links
Software
- Android – installs and runs them
- Android Studio – Google’s Android IDE, which builds APKs and inspects them with the APK Analyzer (Windows, macOS, Linux)
- apksigner – signs APKs and verifies their signatures (Windows, macOS, Linux)
- Apktool – decodes the resources and manifest, and rebuilds APKs (Windows, macOS, Linux)
- jadx – decompiles the DEX code to Java (Windows, macOS, Linux)
- 7-Zip – free archiver that opens the ZIP inside (Windows)
Developers
- Androguard – library that reads APKs, their manifest and DEX code (Python)
Reference
- Application signing – the Android Open Source Project’s description of the APK signature schemes