Sometimes, it can be useful to decompile an APK for Android and try to get Java source code. In this tutorial, you’re going to learn how to achieve that.

There are 2 main ways to process this decompilation. First is to use Smali / Baksmali format with these tools : . Smali is an assembler / disassembler for Dex Format that comes with some tools. Second way is to combine Dex2jar tool then JD-GUI viewer. This is the way we’re going to follow in this tutorial.

1. Get Jar from an APK file

APK file for Android contains some Dex files and here we want to get Jar file corresponding. You must download Dex2jar here :

Once you got Dex2jar, you must generate an APK from one of your projects to try to decompile. I use a Sample.apk that I’ve generated in a previous tutorial. Now, go on directory where you extract Dex2jar and enter the following command line :

d2j-dex2jar.bat -f -o Sample.jar Sample.apk

Now, you got a Sample.jar file in your directory. It contains all the .class of the Sample.apk application. XML content has been ignored. You must tools from Smali like ApkTool to get these files in human read format.

Dex2jar provides also an other tool to assemble / disassemble .class files to an intermediate language named Jasmin that we can update before to repackage application to an APK ! This is out of this tutorial but you can find an example here :


2. View Java classes via JD-GUI

Part of the Java Decompiler Project, JD-GUI is a standalone graphical utility that displays Java source code from .class files. It lets you to browse the reconstructed source code for instant access to methods and fields.

You can freely download the tool here : . Note that plugins for Eclipse and Intellij are also provided.

With our Sample.jar, the result is great :