Decompile Android DEX Files to Java Source Code
A practical, ethical guide to extracting and decompiling DEX bytecode from APKs using jadx, dex2jar, and JD-GUI.
0. Overview
Android apps ship as APKs containing compiled bytecode and resources. At the core are one or more DEX (Dalvik Executable) files—Android’s optimized bytecode derived from Java or Kotlin. Decompiling DEX back to readable Java is useful for debugging, learning, and security research, but it must be done responsibly.
Legal and ethical compliance is mandatory. Only decompile apps you own, have permission to analyze, or that are explicitly open-source.
1. Understanding DEX vs. Java Bytecode
Android compilation happens in two stages:
- Java/Kotlin source → JVM bytecode (
.classfiles) - JVM bytecode → DEX bytecode (
classes.dex) optimized for Android
Decompilation reverses the process:
DEX → JAR → Java source
2. Legal and Ethical Considerations
Before touching any APK, confirm you are allowed to reverse engineer it.
Always respect:
- Copyright law
- The app’s EULA or terms of service
- Local regulations (e.g., DMCA restrictions on bypassing protections)
Ethical use cases:
- Decompiling your own apps for debugging
- Studying open-source apps (e.g., F-Droid)
- Security research with explicit permission
Never:
- Steal code
- Bypass DRM
- Violate user privacy
3. Tools Required
| Tool | Purpose |
|---|---|
| dex2jar | Converts DEX bytecode to JVM JAR files |
| JD-GUI / Luyten | Visualizes JARs as Java source |
| Apktool | Extracts APK resources and DEX files |
| jadx | All-in-one APK/DEX decompiler |
Official links:
4. Step-by-Step Decompilation
There are two common workflows: a manual process (dex2jar + JD-GUI) and a simpler all-in-one process (jadx).
Workflow 1: Manual Decompilation (dex2jar + JD-GUI)
Step 1: Extract the DEX File from the APK
APKs are ZIP archives. You can rename the file or extract it directly.
# Linux/macOS
unzip app.apk -d extracted_apk
# Windows PowerShell (requires unzip utility or 7-Zip)
7z x app.apk -oextracted_apk
Look for classes.dex (and classes2.dex, classes3.dex, etc. for multi-DEX apps).
Step 2: Convert DEX → JAR with dex2jar
# Windows
.\d2j-dex2jar.bat extracted_apk\classes.dex
# Linux/macOS
./d2j-dex2jar.sh extracted_apk/classes.dex
This creates classes-dex2jar.jar near the input file.
Step 3: View JAR as Java with JD-GUI
- Open JD-GUI.
- File → Open → select
classes-dex2jar.jar. - Browse the package tree and inspect classes.
- Save All Sources to export
.javafiles.
Workflow 2: Simplified Decompilation with jadx
jadx handles extraction, conversion, and decompilation in one step.
# GUI
jadx-gui
# CLI
jadx --output-dir decompiled_app --no-res app.apk
Open the APK/DEX and export the Java sources from the UI or CLI output.
5. Troubleshooting Common Issues
Obfuscated Code (ProGuard/R8)
Obfuscation renames identifiers to a, b, c, etc.
Tips:
- Use jadx (often better than dex2jar)
- If you own the app, use
mapping.txtto deobfuscate
dex2jar Errors
OutOfMemoryError is common on large apps.
# Allocate more memory (Windows)
.\d2j-dex2jar.bat -Xmx4g extracted_apk\classes.dex
JD-GUI Shows Empty or Broken Code
- Update JD-GUI or try Luyten
- Re-check that the JAR was generated correctly
Multi-DEX Apps
Apps with >65,536 methods often use multiple DEX files.
Options:
- Use jadx (automatically handles all DEX files)
- Convert each
classes*.dexand merge the output JARs manually
6. Advanced Tips
Deobfuscation
If you have a ProGuard/R8 map:
- Use a mapping viewer or jadx deobfuscation options
- Consider alternative decompilers (e.g., CFR) for cleaner output
IDE Integration
Export .java files and import into Android Studio for better navigation. Expect missing dependencies and build issues on large apps.
Native Code (C/C++)
DEX tools only handle Java/Kotlin. For .so libraries, use Ghidra or IDA Pro.
7. Conclusion
Decompiling DEX files is a powerful skill for learning and analysis. Use tools like jadx, dex2jar, and JD-GUI responsibly, and always confirm that your use case is legal and ethical.