Decompile APK Get Java + Xml Change Apps

Ever felt to change the look and feel of an app or did you accidentally delete your source code. See how to decompile apk to get the source code and how to customize any android app.

This guide is divided into two parts:-

  1. We will see how to decompile apk and extract the source code.
  2. Step by step how to make, look and feel changes to an Android app.

Disclaimer

This guide is purely for educational purpose. We encourage the users to go through the legality before using this guide on any real world application.

Use Case

  • Recover accidentally deleted  source code from the apk file
  • Analysis of security vulnerability and threat detection
  • Modding apps
    • Add a new feature
    • Customize the look and feel
    • Support for non-supported android version

 Limitation

  • Cannot extract the exact same source code as originally written.
  • Some part of the code might not be correctly retrieved.
  • If the app uses a custom framework you will need the custom framework apk file.
  • Most apps do not use custom frameworks.

Requirement

Concepts & Overview

  • Apk file is a zip file.
  • Zip file consists of XML and other android application resources.
  • Apktools decodes the resource files and converts the android bytecode into assembly level samli files.
  • Dex2jar converts the dex files into java bytecode file archived inside the jar file.
  • JD GUI and Luyten decompiles java byte code to java source code file.

Software Downloads & Installations

Create Install Directory
  1. Create an installation directory with any name in a suitable location.
Download and Install Apktools
  1. Download the latest version of Apktools jar file from the website given above.
  2. Copy apktool_x.y.z.jar into the newly created directory
  3. Rename apktool_x.y.z.jar to apktool.jar
  4. Right click and click on “save link as” on apktool.bat link
  5. Copy apktool.bat file in the same directory
Download and Install Luyten
  1. Go to Luyten website and download the latest release of luyten-x.y.z.exe
  2. Copy luyten-x.y.z.exe file in the same directory
Download and Install JD-GUI
  1. Go to JD-GUI website download the latest version of jd-gui-windows-x.y.z.zip
  2. Extract jd-gui-windows-x.y.z.zip file in the same directory
Download and Install Dex2jar
  1. Go to Dex2jar website download the latest stable release of dex-tools-y.x.zip
  2. Extract dex-tools-y.x.zip file in the same directory
  3. Rename d2j-dex2jar.bat to d2j
Download and Install JRE 1.7
  1. Download and install JRE 1.7 from the above link.
  2. In command prompt type  Java – version this should show 1.7.
  3. Might show a higher version if your system has a newer version should still be fine.
Install Zip Signer App
  1. Go to play store and install Zip Signer App on your phone.
Set the Path Environment Variable
  1. Open System Property
    • In Windows 7
      1. Click on the start button.
      2. Right-click on Computer and select properties.
    • In Windows 8 and 10
      1. Right-click on the start button.
      2. Select system properties.
  2. Select advanced system settings.
  3. Under the advanced tab, click on environment variables.
  4. In user variables, select the path and click on edit.
  5. Type semicolon (;) and then the path name of your installation directory.
  6. Then click on OK and then again OK  and then again OK.
Test Installed Software
  1. Open a new command prompt
    1. Click on start
    2. Type in cmd
    3. Then select cmd.exe
  2. Type the command apktool –version
    1. Should print out 2.2

#1: Get Source Code form APK JAVA + XML

Download APK from Play Store

Get the apk file for which you want to extract the source code. If the app is available in the play store, then view our tutorial for downloading the apk file directly from play store.

Decode APK Using Apktool

The second step is to use apk tools to decode the apk and extract Dex files and the resource files.

  1. Open command prompt
  2. Type cd “type here the location of the apk file” and press enter
    • If the location is on a different drive then type the drive letter and then press enter.
  3. For apk with custom framework, install it by typing the command apktool if xyz.apk and hit enter  (Optional)
    • Replace xyz.apk with the name of your framework apk
  4. To decode your app apk file type in apktool d –m app.apk and hit enter
    • Replace app.apk with the name of your application apk

The m option stands for match. This is usually done when you require the exact same resource files, but this prevents rebuilding the apk once you have modified it.

After decoding finishes find the decoded application resources in the same directory in a subfolder named after the application name.

Convert Dex to Jar using dex2jar
  1. Open command prompt
  2. Type d2j app.apk and hit enter
    • Replace app.apk with the name of your application apk

Find the converted  jar file in the same folder

Decompile Jar to Java Source Code

We will be using two applications to convert the jar file into Java code. We will be doing this because the conversion of android Dex code to a Java Jar file is not perfect and certain information is lost. This might lead to improper Java code from the jar file.

Using two applications provides alternate code for a particular file which was not decoded properly. So if for a particular file the code generated by the first application is not correct. Then we can check the code generated by the second application.

Decompile Jar to Java Source Code using JD-GUI
  1. Go to the installation directory and open jd-gui.exe.
  2. Select open a file go to the directory the jar file is present.
  3. Select the jar file and click open.
  4. Click on the file and click on Save All Sources.
  5. Select the directory where you want to save.
Decompile Jar to Java Source Code using Luyten
  1. Go to the installation directory and click on lyuten.exe
  2. Click on file and then click on Open File
  3. Select the directory where the jar file is saved and select the jar file
  4. Click on File and then click on Save All
  5. Select the location for saving the Java code

#2: Modify Apps Using APK Tool

 Pokemon GO Modded Splash Screen
Pokemon GO Modded Splash Screen
Decode Pokemon GO APK Using Apktool

We will decode the apk file without using the m option. Since we now require to rebuild the application after modifying the required files.

  1. Open command prompt.
  2. Type cd “type here the location of the PokemonGo apk file” and press enter.
    • If the location is on a different drive then type the drive letter and then press enter.
  3. To decode your app apk file type in apktool d PokemonGo.apk and hit enter
    • Make sure to delete any previously decoded application in that folder.
Modify Pokemon GO Splash Screen
  1. Open the decoded PokemonGo apk folder.
  2. Click on the assets directory.
  3. Go to bin, then go to data.
  4. Search for the splash.png file in this directory.
  5. Open it using any image editor.
  6. Modify it in any manner I will overlap a cute Pikachu image over it.
  7. Save this modified splash screen by overwriting it on the original image.
Rebuild Pokemon Go Apk Using APkTool
  1. Open command prompt
  2. Type cd “type here the location of the PokemonGo apk file” and press enter.
    • If the location is on a different drive then type the drive letter and then press enter.
  3. Type apktool b PokemonGo
Transfer Apk Using EZ File Explorer
  1. Open the EZ File Explorer app.
  2. Open the menu by tapping on the three lines icon on the top left corner.
  3. Tap on Network then on Remote Manager.
  4. Turn On FTP Server by tapping it.
  5. Open the phone storage by opening the file explorer and type the address shown in the EZ File Explorer app.
  6. Go to the directory with PokemonGo Apk File.
  7. Open PokemonGo directory and open dist folder.
  8. Copy the apk file in the dist folder.
  9. Paste it the phone storage.
Sign Apk Using Zip Signer App
  1. Open the zip signer app, tap on Input
  2. Select the apk file that you just copied to your phone
  3. Tap on sign the file
Install and Test Modified App
  1. Open the phone directory where you saved the apk file using EZ File Explorer
  2. Tap on the pokemongo-signed.apk it will install as an update to the app
  3. Tap install
  4. Open the Pokemon Go app you should see the modified splash screen.

I hope this guide helped you. If yes, consider supporting us. If you are facing some problem following this guide share it below in the comment section. We will try our best to resolve it. You can help others by sharing this guide with your friends whom you think could benefit from it.

At howisolve.com we provide you the with latest updates on technology, tutorials, tips and tricks, troubleshooting guides and much more. Subscribe to our newsletters to get regular updates straight to your inbox. Thanks reading friends see you later bye.

Neil Mahaseth

Hello, friends welcome to HowISolve.com, a community founded by me in June 2015. With the aim to help you solve your everyday tech problems. The motivation for starting this community was instilled from my love for technology and my nature to help others in need. By qualification, I am a technocrat with an M.B.A. and B.Tech. from Narsee Monjee, Mumbai. I have experienced both worlds: corporate and startup. I am currently honing my entrepreneurial skills and trying to add value to people's lives. You can also join us by subscribing to our Newsletters & YouTube channel to be a part of this growing community.

View all posts by Neil Mahaseth →