Search Here

Wednesday, 10 February 2016

How to unpack / pack an APK file


Did you know that when you download an Android App from Google Play or Amazon Store, you are actually downloading 1 single file?

That file has an APK extension and it is a kind of zip file. In fact, if you rename the extension from APK to ZIP and extract it, you will be able to navigate thru its asset files (images, audio,...). But unzipping the file does not make all its content accessible. E.g, if you try to open the AndroidManifest.xml, you will see that its content is not on plain text. So, if you want to correctly unpack all files from the APK, you can use a tool called Apktool.

Here is a step-by-step tutorial to unpack an APK file:

1) Download the apktool file and its system dependency file, both available for free here. (For example, If you are using an MAC, you will have to download: apktool1.5.2.tar.bz2 and apktool-install-macosx-r05-ibot.tar.bz2).

2) Extract both files to same directory (to make things easier :) )

3) Put the apk file that you want to unpack in that same directory

4) Unpack the apk doing with the following command: "./apktool d [your apk file]" (this is a MAC/linux
command, if you are using Windows, it should probably be "apktool d [your apk file]")

 That is it, the apktool will have created a new directory with the same name of your apk file where you will find the apk content.

If you want to pack that directory back again into an apk (let's say, after you edited something), just use the following command: "./apktool b [apk dir name] [apk file.apk]"




Important note: when you unpack and pack back the apk, it loses its android signature. So, if you want to install that apk on a device, you have to sign it again using the android Debug Key or your own key. You can do that by running the following command: "jarsigner -verbose -keystore [your keystore file] [your apk file.apk] [your keystore alias]"