Before proceeding towards explaining how to get source code from APK, we want to clarify that it is for educational purpose only.
APK file contains all the compiled java source in classes.dex file along with many other supportive files. There are some tools available which can be used to get the source code similar to the original source code. These tools are
dex2jar comes in an archive which contains executable files, i.e. executable in Linux and windows both. and Java Decompiler comes with separate installer for Windows, Linux and Mac. Here the steps for using them.
- After downloading the dex2jar archive extract it in a directory, like
- Set the path of the location in Environmental Variable. It makes it easy to use thedex2jar.bat easy.
- Now open the command prompt, and navigate to the folder where you have the apk available.
- The command for converting apk to jar
- This will generate the AppName.jar which can be decoded byjd-gui.
- Download and extract the jd-gui
- It contains a jd-gui.exe, double click it to open
- You can open any .class, .jar file and view its source code.
For Linux (Ubuntu):
- The file is by default downloaded to the Downloads directory, i.e.
- Create a directory in ~/.installed_softs, i.e.
$ mkdir -v ~/.installed_softs
- Extract it
$ unzip ~/Downloads/dex2jar-0.0.9.12-a.zip -d ~/.installed_softs
- Add an alternative in /usr/bin/ by the name dex2jar, so that it can be used from anywhere
$ sudo update-alternatives --install "/usr/bin/dex2jar" "dex2jar" "/home//.installed_softs/dex2jar-0.0.9.12/d2j-dex2jar.sh" 1
- If you apk is available in /home/<username>/apk then give following command
$ dex2jar ~/apk/AppName.apk
- This will create a file AppName-dex2jar.jar in the present working directory.
- Download and extract thejd-gui using the Archive manager.
- Double click on jd-gui to start.
- Browse any jar, class, zip, log or txt file.