Long back in 2016, we published a detailed tutorial on compiling and decompiling APK files using APK Easy Tool. Today, we’ve come up with another utility that lets you compile and decompile APK files even more easily and it’s simply called ‘apktool’, a Java-based tool that works on Windows, Linux, and MacOS. In this apktool tutorial, we’ll see how to use apktool to compile APK from a modified source, decompile APK, edit and recompile APK files, and make an Android app package.
APK modding is quite common in the Android world. By modding an APK file, you can add or remove features from an App, sign it with your own key, change the UI design or theme the UI and add custom translations. APK modding can also be potentially used to inject malicious code inside an App. This is the reason why special care must be taken when installing modified APKs from third-party sources. In this article, we will discuss the basics of how to manipulate an APK to apply modifications to it.
In order to do any sort of modification to an Android APK file, you must first decompile it, edit its contents and then compile it back. Currently, the easiest way to do this is using a special desktop PC tool known as apktool. Apktool is a Java-based utility which can run on Windows, MacOS, and Linux with minimal effort. Once it is set up, it can decompile or compile an APK file with a single command.
Modifying APK files might cause them to become unstable and/or unusable. Be extra cautious when manipulating system APK files, as a wrong change might render your device inoperable. DroidViews does not support in any way modifying APK files to add malicious code in them. This process is strictly prohibited by law.
Set up Requirements
Before you can follow our apktool tutorial, there are a few prerequisites you need to take care of. The only requirement of apktool is Java version 1.8 or greater. You can check if you have Java installed on your machine by opening a command prompt on Windows (click the Start Menu, type cmd.exe and hit enter) or a terminal on MacOS/Linux and giving the command
If this command returns 1.8 or greater, you are good to go. If not, you need to install Java first. You can get Java for your machine here.
Download and Set up apktool
You can download the latest version of apktool by clicking on this link. When the download is finished, rename the file to apktool.jar. You will next need to download a wrapper file, depending on your desktop Operating System. You can get the wrapper file by using the following links. For your convenience, right click on the link and select ‘Save As’.
Save the file as apktool.bat on Windows and apktool on MacOS/Linux:
Also, download the ADB and Fastboot files for Windows, MacOS, and Linux.
Finally, you will need to move both the apktool and wrapper files to a special location so they can be executed everywhere on the system: On Windows, this location is C:\\Windows . On MacOS and Linux, place them under /usr/bin or /usr/local/bin (root required). If you are on Linux or MacOS, make sure that both files have the execute permission set.
To test that everything works as expected, open a command prompt on Windows or a terminal emulator on MacOS and Linux. Then issue the command apktool and hit enter. You should get an output similar to the following:
apktool Tutorial to Edit APK Files
We will cover only the basics of APK file manipulation. This only includes decompilation and compilation. Anything else lies outside of the scope of this article and should be covered in a separate writing.
Decompile, Edit and Recompile APK Files
First, download the APK file which you need to decompile and edit. In this guide, we will be using the Facebook Lite App APK as an example. You can download it here.
Next, open a terminal emulator or command prompt inside the folder you downloaded the APK file to. To do this on Windows, navigate to the folder using Windows Explorer and then type CMD in the address bar as shown below. Hit enter and a command prompt window will open.
Decompiling an APK file is quite simple. You just need to issue a command in the following form:
apktool d <APK filename>
For the Facebook Lite App, this will get into:
apktool d facebook_lite_v126.96.36.199.94.apk
Apktool will create a new folder with the same name as the APK file and place all the App data inside it.
- The res folder contains everything that has to do with translations and user interface layout.
- The smali folder contains App source code in the smali form. Smali is a language type similar to assembly. To make any changes apart from cosmetic ones to an App, these are the files you need to mess with.
- The unknown folder contains everything else that comes packaged inside the APK file but does not follow Google’s guidelines for APK packaging.
- Lastly, AndroidManifest.xml is the Manifest file. This contains information like the App name and characteristics, the Intents it listens to and the Permissions it uses.
Compile APK from a Modified Source
Compiling a modified source with apktool is as simple as decompiling. You can get the job done by just issuing a command in the form:
apktool b <app_source_path>
In our example with the Facebook Lite App, this will get into:
apktool b facebook_lite_v188.8.131.52.94
That is all you need to know if you want to compile and decompile APK files for Android. Stay tuned for special guides about manipulating App icons and colors and adding or removing functionalities to your apps! Try it now and let us know if you were able to decompile and compile an APK. I just hope our apktool tutorial will help you edit APK files yourself.