| 4 min read
It has been over 2 months after I started this blog. Since I work on Android and insides, many of you might be expecting articles related to Android. Today I am going to teach you how to "properly" decompile, edit and recompile android application files (say framework-res.apk which is Android framework. One of the most sensitive apk in Android system, if it is broken your device might end with bootloops)
Caution : This article serves only information on decompiling and recompiling APKs. Do this only if you know what you are doing.
Framework plays important role while decompiling framework dependent apks or system applications. In order to decompile such APK's we need to install framework. Android framework is usually named as "framework-res.apk". Some device manufactures have developed their own framework. E.g. HTC use "com.htc.resources.apk". You need to perform following steps to install framework.
What if a developer wants to work on APKs from different devices? Don't worry, we can manage multiple frameworks by tagging them with separate name. Tagging is explained in example below :
HTC Framework[bash]C:\apktool>apktool if com.htc.resources.apk htc[/bash]
Copy the APK you want to decompile in apktool directory and run following command.
[bash] apktool d nameofapk.apk [/bash]
[bash] apktool d [nameofapk.apk][folder][/bash]
[bash]apktool d music.apk music[/bash]
-s, --no src This will prevent the decompile of the java source. This keeps the APK classes.dex file and simply moves it during re-compile. If your only editing the resources. This is recommended for faster decompile & rebuild.
-r, --no-res This will prevent the decompile of resources. This keeps the resources.arsc intact without any decompile. If only editing Java (smali) then this is the recommend for faster decompile & rebuild.
-d, --debug Decodes in Debug Mode. Currently not supported. Needs rewrite.
-b, --no-debug-info Prevents baksmali from writing out debug info (.local,.param,.line, etc). Credits: Ziggy. Perferred to use if you are comparing smali from the same APK of different versions. The line numbers and debug will change among versions, which can make DIFF reports a pain.
-f, --force Force delete destination directory. Use if trying to decompile to a folder that already exists.
Well, changing framework or APK content can break the package. Separate article on "Troubleshooting apktool errors" is on the way, you will learn about all the errors and their solutions.
Recompiling framework or APK is easy but it has been a real pain for many developers. Usually, it takes hours to fix errors that we get while compiling frameworks or apk. Don't worry about that, my next article will be on troubleshooting such errors.
Once you have finished with editing, just run the following command..
[bash]apktool b [Directory-in-which-package-is-decompiled][/bash]
You are not done yet. Some APKs needs to be signed. There are many APK signing tools available online. However in my next article, I will share my own APK multipurpose tool which Decompiles, Compiles, Optimizes and signs APKs :-)