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.
Warning
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.
Preparations
- 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
You will see a lot of activity on your command screen, the output should be similar to this:
- 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
You will get a similarย output once you press enter after typing the command:
- 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
Once you press enter, you will see a lot of lines scrolling up. Don’t worry, it is just aligning your app package. At the end you should see a success message like this:
- 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.
https://uploads.disquscdn.com/images/9d89e2ada709e3a82199098f7e2531db24e133562165a83ac617a7f38d018667.jpg Followed all the steps it is not showing smali folder and certain exceptios are occuring(link below) https://uploads.disquscdn.com/images/2ed5b90c860299c9e173b0f822a3307458ee3731bc6238aa26514d078a67a26e.jpg
From the decompiled code, how can I make android studio project so that I can add more features to it?
In step 5 it says now install the framework on your device. It doesn’t say to plug the device into the computer. Am I missing something?
I am trying to modify a game so it runs on my rooted tablet. I found the smali files that detect root but I am not sure what I need to change in order to make it work. Any ideas would be much appreciated, thank you.
Below are the lines that detect root
Line 11: value = Loom/gamevilusa/mlbpi15/android/google/global/normal/UnityPlayerNativeActivity;->OnHackDetected (ILjava/lang/String;)V
Line 60: const-string v1, “OnHackDetected”
Line 87: const-string v1, “OneHackDetected”
Line 112: const-string v1, “OnHackDetected”
Line 137: const-string v1, “OnHackDetected”
Line 153: const-string v1, “OnHackDetected”
Line 68: .method public OnHackDetected (ILjava/lang/String;) V
Line 512: invoke-virtual (p0, v0, v2), Loom/gamevilusa/mlbpi15/android/google/global/normal/UnityPlayerNativeActivity;->OnHackDetected (ILjava/lang/String;)V
Line 52: .method public OnHackDetected (ILjava/lang/String;) V
Line 18: .method public abstract OnHackDetected(ILjava/lang/String;)V
Every time I try and edit any apk after decoding and extracting it, when I try and recompile it I get an exception. Even if I decompile and simply recompile without changing anything I still get brut exception errors (I use apktool)
I done all the steps but that app cannot be installed ๐ …
Hi, thanks for this tutorial!
So, everything went well until i tried to install the apk.
I get the msg: Application Not Installed
How can i solve it?
Hi, same issue here. Were you able to resolve this? Please help.
Showing error
E:New foldermfastboot-v2>apktool if framework-res.apk
Exception in thread “main” brut.androlib.AndrolibException: Could not decode ars
c file
at brut.androlib.res.decoder.ARSCDecoder.decode(Unknown Source)
at brut.androlib.res.decoder.ARSCDecoder.decode(Unknown Source)
at brut.androlib.res.AndrolibResources.installFramework(Unknown Source)
at brut.androlib.Androlib.installFramework(Unknown Source)
at brut.apktool.Main.cmdInstallFramework(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000
at brut.util.ExtDataInput.skipCheckInt(Unknown Source)
at brut.androlib.res.decoder.StringBlock.read(Unknown Source)
at brut.androlib.res.decoder.ARSCDecoder.readPackage(Unknown Source)
at brut.androlib.res.decoder.ARSCDecoder.readTable(Unknown Source)
… 6 more
E:New foldermfastboot-v2>