Flexibility and customizability are the main things a Smartphone owner always wants. If you’re not satisfied with a segment in your Smartphone, you’re not required to mourn about it, you just need to know how to change it. However, you will not get this opportunity on any proprietary OS like IOS or Windows, this is possible in open source operating systems.
Open Source, the name itself says that it is open to everyone and anyone who is capable of handling it. Android is one such Open Source OS and is the most popular OS among the smartphones. It gives the flexibility to change the parts of OS that doesn’t impress you. Even you can change the look and feel of the apps on Android.
Android System apps can be modded & themed which can be used in making Custom ROMs. So if you’re interested in developing mods and Custom ROMs or if you want to do some simple modifications to the existing rom, you should know how to decompile and recompile APK files. Decompiling an APK allows you to modify the look and functionality of the app, so you can change the app according to your requirement. Once you’ve modded it, you should recompile it and optimize it to make efficient use of your Smartphone’s resources.
Today we will show how to decompile and recompile APK Files and then optimizing it in a simple way. Follow the guide carefully to decompile and recompile APK files to make themes and much more.
This Guide involves a lot of advanced stuff. Be extra cautious while you follow this guide, otherwise, you might end up with a bricked device. You alone are responsible for any consequences that might occur during the process. We shall not be held responsible for any damage to your device.
- Either setup ADB and Fastboot on your computer, or download the Minimal Fastboot tool and unzip it: mfastboot-v2.zip
- Download the Apktool files → Click Here
HOW TO DECOMPILE AND RECOMPILE APK FILES
- Download the ADB files and extract them to a folder on your PC. Avoid extracting them on Desktop, because the black spaces in the username might pop some errors during the decompiling and recompiling.
- Download and extract the Apktool files in the same folder where you extracted the adb tools.
- We are taking SystemUI.apk as the test apk to decompile and recompile, you can take any apk you want to mod. So you will have similar files:
- Now open a command prompt in the ADB folder by holding Shift key and Right Click in the empty space in the folder.
- Now you need to install the framework on your device. You can install the SystemUI.apk alone, but installing the framework-res.apk is also recommended in case of system apps. Type the following command to install:
apktool if <app-name.apk>
In this case:
apktool if framework-res.apk
- Now similarly install the SystemUI.apk using the command:
apktool if SystemUI.apk
- Now we are ready to decompile the SystemUI.apk file. Type the following command to decompile the file:
apktool d <apk-name.apk>
In this Case:
apktool d SystemUI.apk
- As you can see that the decompiling process takes resource table from the framework we installed in the previous steps. After the APK is decompiled you will see a folder in the ADB tools directory itself with the name of the decompiled apk. Inside the folder, you will get the folders similar this:
- These folders are more or less similar to an APK file. The res folder contains all the media files including images, ringtones and many more. It also contains the front end XML files which can be used to alter the look and feel of the app you’ve decompiled.
- The Smali folder is the tricky part, it contains the processed Java files in the form of .smali files. This folder only appears if the APK is deodexed, otherwise, these files are compressed in a single file with an extension .odex which will be found outside the APK. So you won’t get the Smali files unless the APK is deodexed.
- The Smali files are responsible for the functionality of the app, and handling them would create direct impacts to the app. So be careful while editing these files as they might cause unexpected responses on your device.
- Start your tinkering and make the necessary modifications to the APK, once finished we can recompile the APK.
- To recompile the APK type the following command:
apktool b <decompiled-folder-name>
In this case:
apktool b SystemUI
- Now you can find the recompiled APK in the dist folder in the decompiled APK directory (SystemUI\dist)
- Now the APK is built, but due to the modifications made, the APK might not be compact and uses much more system resources than it actually should. To avoid this, we will align the package using Zipalign tool.
- Download the Zipalign tool and extract it in the same folder where you have placed the recompiled APK. → Click Here To Download
- Now type the following command to Zipalign the APK
zipalign -v 4 <recompiled-apk.apk> <final-apk.apk>
In this case:
zipalign -v 4 SystemUI.apk SystemUI-final.apk
- Now you will see a new file created in the folder with the name SystemUI-new.apk (or whatever APK you modded) This is the final APK which is optimized using the Zipalign tool.
- You can flash this modded app in any possible way, you are comfortable with.
That’s it, you have now decompiled an APK, then modded it, recompiled the modded APK and finally you have optimized its performance using the Zipalign tool.
Lot of things to learn in a single tutorial, right? Leave your feedback in the comments section below.