This article was first published on:Walker AI

When we want to understand an APP, the best way to learn is to decompile its APK file. After decomcompiling APK, we can see the resource file (image), layout, style, related implementation code used to develop the application. Learning these resource files will help improve the development technology.

This article mainly introduces the method of APK decompilation, hoping to help you.

1. Prepare tools

1.1 Tool Introduction

  • Apktool: Obtain resource files. You can extract image files and layout files for viewing.
  • Dex2jar: Decompile APK into Java source (classes.dex into jar files).
  • Jd-gui: Check the classes. Dex jar file in APK. Download apktool, dex2jar, and JD-gui.

1.2 Configuring Environment Variables

Download the latest JDK from the Oracle website and configure environment variables.

Figure 1. Configuring environment variables

2. APK decompilation process

2.1 Perform APK Decompilation

(1) In order to facilitate the process, we put the downloaded Apktool, Dex2JAR, JD-GUI and the APK files to be decompiled under the same folder.

Figure 2. Folder interface

(2) Open CMD command line, go to the folder where the APK file is stored, and run the jar file apkTool_2.5.0. jar to decompile the APK file. The command is as follows: Java -jar jar specifies the package name. Jar

Jar d -f C:\Users\ly\Desktop\chaibao\fanbianyibao.apk -o 123

Jar will decompile the “fanbianyibao.apk” file in the “C: Users\ly\Desktop\chaibao” directory. Then save the decompiled files in the “C: Users\ly\Desktop\chaibao\123” folder.

Figure 3. Command prompt interface

(5) After the decompilation succeeds, a folder named “123” will be added to the specified file directory.

Figure 4. Specify file interface

(6) Open the “123” folder, you can see the generated files after decompression, among these generated files and folders, we are interested in the res folder and the androidmanifest.xml file, open the RES folder, which stores the XML files we are interested in, as shown below:

Figure 5. Add folder list

Figure 6. Add the res folder list under folder

APK resource file introduction

The figure above shows the decompiled resource files of APK files. Here is a brief introduction to these files:

  • Meta-inf: saves the APP signature information.
  • Classes.dex:. Dex is an executable file on the Dalvik virtual machine that needs to be converted to a JAR file using dex2jar.
  • Androidmanifest.xml: An Android manifest file that provides the necessary information about an application to the Android system.
  • Assets: Stores some resources, files, fonts, sounds, etc.
  • Lib: stores third-party libraries.
  • Original: Stores undecompilated androidmanifest.xml files.
  • Res: Stores resource files, such as images, colors, and characters.
  • Smali: Stores Java compiled Smali code, which is equivalent to the language running on the Android VIRTUAL machine.

2.2 Decompilate APK using dex2JAR to get Java source code

(1) Change the decompiled APK to.rar or.zip and unzip it to get the classes.dex file, as shown in the following figure:

Figure 7. Modify the folder suffix and unzip it

(2) Put the obtained classes.dex into the folder “dex2jar-2.0”, as shown in the figure:

Figure 8. Moving classes.dex

(3) Navigate to the directory where dex2jar.bat resides on the CLI and run the d2j-dex2jar classes.dex command to decompile classes.dex into a JAR package.

Figure 9. Executing the command line

Once you have the classes-dex2jar.jar file, you can use the JD-GUI tool to decompress the class file into Java source code.

Figure 10. File list display

(5) Start the JD-GUI tool, select file-OpenFile, select classes-dex2jar.

Figure 11. Launching the JD-GUI tool

Figure 12. Source code display

3. Summary

If an error occurs during apktool decompilation, the apktool version may be too low. You are advised to download the latest version and try again. But please don’t decompile developers’ APK, respect others’ work!


PS: more dry technology, pay attention to the public, | xingzhe_ai 】, and walker to discuss together!