APK Inspector: Building an On-Device APK Explorer and Decompiler
An Android app that unpacks, indexes and decompiles APKs entirely on the phone — with no network permission at all. The binary XML decoder written from scratch, the indexing strategy that keeps it fast, and the viewer that scrolls a 200,000-line dump.
Author
Aman Kumar
Published
Sep 19, 2026
Project
APK Inspector
TL;DR
An Android app that opens an APK, walks its package tree, and shows any class as Java or smali — plus the file tree, decoded manifest, signing certificates and per-DEX statistics. Everything runs on the phone, and there is no INTERNET permission in the manifest.
Binary AndroidManifest.xml decoder written from scratch. No external tool.
Only DEX class_def tables up front. Members parsed on demand.
One list row per source line, so a 200,000-line dump still scrolls.
Why Build This At All
Inspecting an APK is a desktop ritual — pull the file off the device, move it to a laptop, open a decompiler GUI. But most of what I actually want to know is small:
debuggable?Two-minute questions that cost a fifteen-minute round trip. The on-device alternatives are either closed-source utilities with an ad SDK bolted on, or web services whose first step is uploading the APK to someone else’s server — a non-starter for a pre-release build or a client’s app.
The constraint that shaped everything
No network access at all. Not “we promise not to upload” — there is no INTERNET permission in the manifest, so the platform enforces it and anyone can verify it by opening the app in the app.
Which means unpacking, binary XML decoding, DEX parsing, disassembly and decompilation all run in one Android process, on a device that might be a mid-range phone.
What Is Actually Inside an APK
An APK is a ZIP
A standard ZIP reader opens it — which also means it carries every classic ZIP risk.
The manifest is not text
It is compiled binary XML. A text viewer shows noise, which is why most tools shell out to decode it.
Code lives in DEX
One or more classes*.dex files of Dalvik bytecode, each opening with a fixed 112-byte header.
Two views of the same code
Smali is the exact bytecode, so it is what you trust. Java is the readable summary you reach for first.
Showing both, one tap apart and able to jump to the same member in either, means you never have to pick one up front.
How the App Is Put Together
Every screen is one step deeper into the same file:
Four packages, strict one-way dependencies — ui may call core, never the reverse:
Everything that touches an APK
Unpacking, binary XML decoding, the class index, the disassembler, the decompiler. 9 files, ~1,700 lines. No Android UI types — which is what makes it testable on a plain JVM.
Twenty files, one row layout
Six tabs over an open APK, plus the class screen and code viewer. Every list renders through one shared row helper — why the screens look like a single product.
Plain data
~100 lines of data classes — node tree, package info, certificates, DEX entries.
Formatting, colour, errors
Formatters, syntax highlighters for Java/smali/XML, preferences, and the error translator every failure routes through.
Opening an APK runs a six-stage pipeline, each stage reporting a real percentage rather than an indeterminate spinner:
Open pipeline
What I Used, and What For
A few well-chosen libraries for the formats that are genuinely hard — and hand-written code wherever the format is small enough to own outright.
| Piece | What it does |
|---|---|
| Kotlin + XML views | The whole app. No Compose — view binding and RecyclerView give finer control over the code viewer, the screen that had to be fastest. |
| Material 3 | Theming, light and dark, Material You, edge-to-edge on Android 15. |
Coroutines + StateFlow | Unpacking, indexing and decompiling off the main thread, with progress the UI can observe. |
| Standard ZIP reader | Unpacking the archive. |
| Hand-written binary XML decoder | The manifest and every compiled res/*.xml. Written in-project. |
| Hand-written DEX header reader | Per-DEX statistics, straight from the 112-byte header. |
| A DEX/smali library | Loading DEX files and producing smali — a format big enough that owning a parser would be its own project. |
| A Java decompiler engine | Reconstructing readable Java from bytecode. |
RecyclerView | The code viewer, one row per source line. |
| SAF + MediaStore | Receiving a file without storage permissions; saving exports to Downloads/. |
Five Decisions That Made It Work
Five problems, and the shape of each answer:
Writing the binary XML decoder by hand
8 chunk typesChallenge
The manifest is compiled binary XML — a chunked format with a string pool and typed attribute values.
Approach
A self-contained chunk parser with no dependency beyond the JDK. Unknown chunks are skipped by their own declared size rather than treated as errors.
Result
One decoder covers the manifest and every compiled res/*.xml — so tapping a layout file shows readable XML, for free.
Indexing only what is cheap
class_def onlyChallenge
A large app holds thousands of classes across several DEX files. Parsing every member up front is slow and almost entirely wasted.
Approach
Read only the class_def table per DEX — type, name, package, access flags, source DEX. Full member lists are parsed per class, on open.
Result
The package tree appears quickly and memory stays flat no matter how large the app is.
Reading the DEX header directly
112 bytesChallenge
The statistics tab wants counts of strings, types, fields, methods and classes for every DEX in the APK.
Approach
Parse the fixed-size header at the start of each file. No DEX library involved — just the right offsets.
Result
Statistics render instantly at any file size, including method references charted against the 65,536 ceiling.
One list row per source line
200,000 linesChallenge
A whole-DEX smali dump runs to hundreds of thousands of lines. A single text view freezes the app on open.
Approach
Split on newlines and make each line its own list row, so only the lines on screen ever render. Highlighting is lazy, with a 600-line cache.
Result
Huge dumps open and scroll like any other screen — and find-in-file, line numbers and wrap all build on the same structure.
Keeping the heavy component isolated
0 dependentsChallenge
Decompiling is the one operation that loads an entire APK into memory.
Approach
A strict one-way dependency: nothing else in the app is allowed to depend on the decompiler.
Result
Structure, manifest, DEX statistics and smali all work regardless — and decompilation can be switched off entirely in Settings.
Hardening an App That Eats Untrusted Files
Every input this app takes is untrusted by definition.
No INTERNET permission
The one declared permission is QUERY_ALL_PACKAGES, for the installed-apps picker. Remove it and file-opening still works.
Two-layer zip-slip guard
Entry names are filtered, then every resolved path is independently checked against the work directory before a byte is written.
Every error is translated
Raw exception text never reaches the UI — internal prefixes stripped, common failures mapped to plain sentences.
Failures stay contained
Out-of-memory conditions on very large archives are caught and reported in place, not allowed to take the process down.
The traversal guard being two independent layers is deliberate: string filtering alone has a long history of being defeated by encoding tricks, so a canonical-path comparison backs it up.
What’s next
Parse resources.arsc — resolve the raw resource IDs in the decoded manifest, and open the door to a proper resources browser.
Cross-references — “find usages” and string search across a DEX, the features I most want on an unfamiliar app.
Conclusion
Take away the server and every easy answer goes with it. What’s left is a long run of decisions about how much work a screen is allowed to do before anyone notices — and getting those right is the app.
It fits in a pocket now. That still feels like it shouldn’t be true.
References
- Dalvik Executable format — the DEX header layout, including every field the statistics tab reads.
- Enable multidex for apps over 64K methods — where the 65,536 method-reference ceiling comes from.
ResourceTypes.h— AOSP’s description of the binary XML chunk format and typed values.- CWE-22: Path Traversal — the class of bug the zip-slip guard exists to prevent.
- Storage Access Framework — receiving a file without storage permissions.
RecyclerViewperformance — background for the one-row-per-line viewer.
APK Inspector links against open source components under BSD-3-Clause, Apache-2.0 and SIL OFL 1.1. The required notices ship inside the app, under About → Open source licences.