[GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

A_U

Senior Member
Jun 6, 2012
3,330
4,588
0
Wichita
www.facebook.com
Hello :)

I want to keep things simple and very easy. I will write a 5 step guide for setting up apktool and start modifying your app's or any other android framework. This guide will be strictly for windows users, since setting up and using apktool in windows is the easiest.
So lets begin -



What you need before you learn how to use apktool -

  1. A computer running windows
  2. A working internet connection for downloading the following -
    • JAVA SDK and JRE
    • Android SDK
    • Apktool core tool
    • Sign apk tool
  3. Basic command prompt commands and path knowledge
  4. A good linux format code editing program like NotePad ++ [Get it from HERE]


STEP 1 - Install JAVA - Go HERE



  • Just go to the above website and download java SDK and JRE.
  • We mostly use only SDK libraries but JRE is required when you want to modify games or apps like whatsapp. So its best if we install both.
  • install them in any directory for example C:\ drive and you are good to go to next step 2.

STEP 2 - Install Android SDK- Go HERE



  • Just go to the above website and download the SDK.
  • Install it in an easy path. For example - C:\android
  • The short path will be useful when you are using adb for logcat purposes, since typing in a long path every-time you want to access the adb executable file is painful.
  • So once you installed the SDK move on to next step 3

STEP 3 - Download Apktool - Go HERE



  • For downloading apktool related files, you need to go HERE
  • Download latest apktool version, currenlty 1.5.2
  • Download the batch file and aapt.exe
  • Create a folder anywhere in the pc and put all the apktool.jar, aapt.exe and the batch script in that folder. [see screenshot]
  • This will be the operating folder for you now.
  • Next move to next step 4

STEP 4 - Using apktool for decompiling anything



  • Open command prompt
  • navigate to the folder where you placed apktool.jar, batch script and the aapt.exe [see screenshot]
  • For this guide i am using a simple framework-res.apk for reference.
  • Once you are in the folder via cmd prompt, you need to install the file using the " IF " command
  • type the following command -

    Code:
    [B]apktool if [I]name-of-the-app[/I] .apk[/B]
    For example, once the command is executed correctly, it will look like this -

    Code:
    [B]apktool if framework-res.apk[/B]
  • Once the app is installed you need to decompile it.
  • For decompiling use the command "d". The "d" stands for decompile.

    Code:
    [B]apktool d [I]name-of-the-app[/I] .apk[/B]
    For example -

    Code:
    [B]apktool d [I]framework-res.apk[/I][/B]
  • After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mod's.

    For example, here's how it will look once the app is decompiled -

  • Then after you are finished with your modding, you need to recompile your app for using it.
  • To recompile the app use the following command " B ". The "b" simply means recompile.

    Code:
    [B]apktool b [I]name-of-the-app-folder[/I][/B]
  • NOTE - While recompiling the app, you just need to type the name of the folder the app's files contains.
    For example -

    Code:
    [B]apktool b [I]framework-res[/I][/B]
    framework-res is the name of the folder

  • The final modded app will be in the dist folder located inside the original app folder created by apktool.

    For example -

  • Congrats ! If everything went well, you successfully created a modified app ! :)
  • Now the most important step is below in step 5


NOTE - You MUST follow the step 5. Or else the app wont work and when you try to push it into system, the rom will be stuck in bootloop XD

STEP 5 - Signing the apk

  • to sign an apk download the "sign-apk.rar" from below attachements
  • extract it to any place.
  • open a new command prompt and change into the sign-apk directory using cmd
  • move the modified-unsigned apk into this folder [see screenshot] -
  • then type the following command -

    Code:
    [B]java -jar signapk.jar certificate.pem key.pk8 [I]path-of-the-folder-contaning-the-apk .apk path-of-the-new-signed-apk .apk[/I][/B]
    For example -


    Code:
    [B]java -jar signapk.jar certificate.pem key.pk8 [I]framework-res.apk framework-res-signed.apk[/I][/B]
  • Once compiled, the signed apk will be found in the same folder.
  • This is FINAL APK. :)
  • Simply rename it to the original apk and push it into the system ! DONE ! :D


If you have any errors or problems related to apktool, post them here, I will try to solve them. :)
 

Attachments

A_U

Senior Member
Jun 6, 2012
3,330
4,588
0
Wichita
www.facebook.com


STEP 1 : Rooting MAC

If you have a mac, apk manager doesn't work on macs. So, you must use apktool. To set up apktool, you must have root mode enabled on your mac. To do that, simply follow these steps:
  • Open system preferences
  • Open accounts
  • Go to login options
  • Hit join next to network account server
  • Select open directory utility
  • Click the lock at the bottom of the window that pops up and enter an admin password
  • Then, go to the top bar on your mac, hit edit, and select enable root mode


STEP 2 : SETTING UP APKTOOL

Once you have root mode enabled, you're ready to set up apktool :
  • From the apktool website, download apktool-latest-version.tar.bz2 and apktool-install-macosx-latest-version.tar.bz2
  • Next, open terminal type :

    Code:
    [B]su
    tar -C /usr/local/bin -xvf <zipped file name>
    tar -C /usr/local/bin -xvf <zipped file name> (for the second file)[/B]
  • Now to confirm it worked, type "apktool" no quotes
  • You should get a help menu for apktool
  • If you got it, you're good to go to next step.


STEP 3 : USING APKTOOL

Now, once you have it set up, you're ready to go! After typing apktool, you'll see the help menu which'll give you the commands available for apktool, but I'll go over the basic ones here.
  • For installing frameworks or apps
    Code:
    apktool if
  • This command will decompile the apk
    Code:
    apktool d "apk path here"
  • This command will build an apk from a previously decompiled one
    Code:
    apktool b "decompiled apk path here"

----------------------------------------------------------





Download the apktool.java file along with other files, as shown above. Extract them to the desktop.

Now open terminal and type line by line :

Note : "android" in all the below commands is my username. So it changes according to your pc name ;)

We are giving root permissions for the 3 files that you extracted above.
Code:
chown -R android:android '/home/android/Desktop/apktool.jar'
press enter

Code:
chown -R android:android '/home/android/Desktop/aapt'
press enter

Code:
chown -R android:android '/home/android/Desktop/apktool'
press enter


Next make all 3 files executable by doing the same thing one at a time pressing enter in between each one:
Code:
sudo chmod +x '/home/android/Desktop/apktool.jar'
after the first it will ask you for your password type it, you shouldnt need it after that for the rest

Code:
sudo chmod +x '/home/android/Desktop/aapt'
Code:
sudo chmod +x '/home/android/Desktop/apktool'
now we need to move all three files to bin folder to do it type this command and enter your password:
Code:
gksudo nautilus
a new window should pop up on the left click on "filesystem/usr/local/bin, then drag all three folders into the bin folder and close it.

APKTOOL is now ready and make your modifications on a linux distro easily :)
 
Last edited:

gabrielking9

Senior Member
Feb 12, 2012
2,331
410
0
Recife
Hey i am stuck at the part
" tar -C /usr/local/bin -xvf <zipped file name> "
What i need to do? I have the "apktool-install-macosx-r05-ibot.tar.bz2" file and the folder "apktool-install-macosx-r05-ibot" which one should i put in it? and i need put it with directory For example: /user/gabriel/desktop/apktool-install-macosx-r05-ibot ??? and i need put this "><" ??????
 
Last edited: