Note: All of the following instructions apply universally (aka to all OSes) unless otherwise specified.
Prerequsites
You will need:
- A working Java installation
- A working terminal/command prompt
- A computer
- An APK file
Steps
Step 1: Changing the file extension of the APK file
-
Change the file extension of the
.apk
file by either adding a.zip
extension to the filename, or to change.apk
to.zip
.For example,
com.example.apk
becomescom.example.zip
, orcom.example.apk.zip
. Note that on Windows and macOS, it may prompt you whether you are sure you want to change the file extension. Click OK or Add if you’re using macOS:
Step 2: Extracting Java files from APK
-
Extract the renamed APK file in a specific folder. For example, let that folder be
demofolder
.-
If it didn’t work, try opening the file in another application such as WinZip or 7-Zip.
-
For macOS, you can try running
unzip
in Terminal (available at/Applications/Terminal.app
), where it takes one or more arguments: the file to unzip + optional arguments. Seeman unzip
for documentation and arguments.
-
-
Download
dex2jar
(see all releases on GitHub) and extract that zip file in the same folder as stated in the previous point. -
Open command prompt (or a terminal) and change your current directory to the folder created in the previous point and type the command
d2j-dex2jar.bat classes.dex
and press enter. This will generateclasses-dex2jar.jar
file in the same folder.- macOS/Linux users: Replace
d2j-dex2jar.bat
withd2j-dex2jar.sh
. In other words, rund2j-jar2dex.sh classes.dex
in the terminal and press enter.
- macOS/Linux users: Replace
-
Download Java Decompiler (see all releases on Github) and extract it and start (aka double click) the executable/application.
-
From the JD-GUI window, either drag and drop the generated
classes-dex2jar.jar
file into it, or go toFile > Open File...
and browse for the jar. -
Next, in the menu, go to
File > Save All Sources
(Windows: Ctrl+Alt+S, macOS: ⌘+⌥+S). This should open a dialog asking you where to save a zip file named `classes-dex2jar.jar.src.zip” consisting of all packages and java files. (You can rename the zip file to be saved) -
Extract that zip file (
classes-dex2jar.jar.src.zip
) and you should get all java files of the application.
Step 3: Getting xml
files from APK
- For more info, see the
apktool
website for installation instructions and more -
Windows:
- Download the wrapper script (optional) and the apktool jar (required) and place it in the same folder (for example,
myxmlfolder
). - Change your current directory to the
myxmlfolder
folder and rename the apktool jar file toapktool.jar
. - Place the
.apk
file in the same folder (i.emyxmlfolder
). -
Open the command prompt (or terminal) and change your current directory to the folder where
apktool
is stored (in this case,myxmlfolder
). Next, type the commandapktool if framework-res.apk
.What we’re doing here is that we are installing a framework. For more info, see the docs.
- The above command should result in “Framework installed …”
-
In the command prompt, type the command
apktool d filename.apk
(wherefilename
is the name of apk file). This should decode the file. For more info, see the docs.This should result in a folder
filename.out
being outputted, wherefilename
is the original name of the apk file without the.apk
file extension. In this folder are all the XML files such as layout, drawables etc.
- Download the wrapper script (optional) and the apktool jar (required) and place it in the same folder (for example,
Source: How to get source code from APK file – Comptech Blogspot