Decompile and Recompile Android APK file

Some time we feel that we want few modifications in our favorite APPs. But we are not able to do so. There is a way to achieve this. It’s simple, but not successful in 100% cases. But you can give a try. The process is decompiling the APK file and again recompiling it. For this tutorial I tested the process in both Ubuntu and Windows7

Before you start first get an APK file of your choice. (If you are going to modify any app with this process, please read the license doc of the app before starting)

Download the below files:

For Windows:

1. wrapperscript
2. apktool
3. Zipalign

For Linux:

1. apktool
2. wrapperscript
3. Zipalign

In Linux do the following before you start:

Check the Java version by running the following command in Terminal:
$ java

If you have lower version of java then run the below command to install JDK 7.
$ sudo apt-get install openjdk-7-jdk

Now the process is same for Windows and Linux. I am describing here for Windows. You can do the same thing for Linux. If you are getting any trouble while doing in Linux, please put a comment in the comment section. I will try my best to help you out.

Decompiling the APK file:

Download the wrapperscript and apktool files and place them in a single folder. The apktool jar file comes with a name like this: apktool_2.0.0rc4.jar. Rename it to apktool.jar.
1. Place the .apk file in the same folder.
2. Now open commend prompt and cd to the folder where you kept the files mentioned above. In windows you can simply do this by opening the destination folder and do a Shift+right click and select the ‘Open Command Window here’ option.

3. Now run the below command:

apktool if <your-app-name.apk>

This will install the framework in your system.

For decoding and building apps, Apktool needs some framework (some code and resources that are built into the Android system on your device) files. Standard Android framework is embedded into apktool, so for most apk files you don’t need to do anything. But some manufacturers like HTC, add their own framework files and use them in system apps. To use apktool against such apps, you must pull framework from a device and install/register it to apktool.

4. Now run

apktool d < your-app-name.apk >

this will decompile your .apk file. After completing this you will see a folder has been created with the same name of the apk file.

Now quickly read the below points to get an overview about the files present inside the folders. For further knowledge you can do research on your own.

a. In assets folder all fonts are available.
b. In res folder all the media files are available.
c. In Smali folder the processed Java files are available in the form of .smali files. These files are responsible for the functionality of the app. I will suggest, not to change these files. If you really want to change functionality then do some research on these files.

Recompiling the APK file:

To recompile the APK type the bellow command:

apktool b <decompiled-folder-name>

After completing this process you can find the APK in a folder, named ‘dist’ in the decompiled APK folder.

Now extract the downloaded zipalign tool in the same folder where you have placed the recompiled APK.
and run the following Command:

zipalign -v 4 <recompiled-apk.apk> < final-apk.apk>

At the end of this process you should get a success message. Enjoy!
If you get any error or any problem following this process, please leave a comment, I will try to help you.

 

 

 

Arijit Naskar

Arijit Naskar is a Software Developer and QA, also founder of alltechstories.com a popular tech tutorial & how-to website since 2014. He loves to explore new technologies and writing blogs.

You may also like...