Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,785,193 Members 36,539 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
A_U
Old
#1  
Recognized Contributor / Themer - OP
Thanks Meter 4,568
Posts: 3,223
Join Date: Jun 2012
Info [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

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:
    apktool if name-of-the-app .apk
    For example, once the command is executed correctly, it will look like this -
     

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

    Code:
    apktool d name-of-the-app .apk
    For example -

    Code:
    apktool d framework-res.apk
  • 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:
    apktool b name-of-the-app-folder
  • NOTE - While recompiling the app, you just need to type the name of the folder the app's files contains.
    For example -

    Code:
    apktool b framework-res
    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


Quote:
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:
    java -jar signapk.jar certificate.pem key.pk8 path-of-the-folder-contaning-the-apk .apk path-of-the-new-signed-apk .apk
    For example -
     


    Code:
    java -jar signapk.jar certificate.pem key.pk8 framework-res.apk framework-res-signed.apk
  • 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 !


If you have any errors or problems related to apktool, post them here, I will try to solve them.
Attached Files
File Type: zip SignApk.zip - [Click for QR Code] (9.2 KB, 10135 views)
Samsung Galaxy Note 2 (GT-N7100)
Baseband : NG4
ROM : Dr. Ketan V9

 




My Facebook page | My XDA Contributions



Previous Devices -

Pandigital Supernova Tablet
Samsung Galaxy Ace
Samsung Galaxy Mini
The Following 112 Users Say Thank You to A_U For This Useful Post: [ Click to Expand ]
 
A_U
Old
(Last edited by A_U; 19th August 2013 at 08:28 PM.)
#2  
Recognized Contributor / Themer - OP
Thanks Meter 4,568
Posts: 3,223
Join Date: Jun 2012


 
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:
    su
    tar -C /usr/local/bin -xvf <zipped file name>
    tar -C /usr/local/bin -xvf <zipped file name> (for the second file)
  • 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
Samsung Galaxy Note 2 (GT-N7100)
Baseband : NG4
ROM : Dr. Ketan V9

 




My Facebook page | My XDA Contributions



Previous Devices -

Pandigital Supernova Tablet
Samsung Galaxy Ace
Samsung Galaxy Mini
The Following 12 Users Say Thank You to A_U For This Useful Post: [ Click to Expand ]
 
dzeig
Old
#3  
dzeig's Avatar
Senior Member
Thanks Meter 68
Posts: 290
Join Date: Jan 2013
for decompiling - compiling apk, use apk multi tool, waaay simpler. (and stable).
 
gabrielking9
Old
#4  
Senior Member
Thanks Meter 398
Posts: 2,240
Join Date: Feb 2012
Location: Recife
Default Re: [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Thanx will read it

Sent from my GT-S5570 using xda app-developers app
Press thanks if i helped you.

Device
Samsung Galaxy Mini S5570B - DEAD
Motorola Razr D1 XT916 - LIVE
 
A_U
Old
#5  
Recognized Contributor / Themer - OP
Thanks Meter 4,568
Posts: 3,223
Join Date: Jun 2012
Quote:
Originally Posted by dzeig View Post
for decompiling - compiling apk, use apk multi tool, waaay simpler. (and stable).
yea its easier but i prefer apktool simply...
Samsung Galaxy Note 2 (GT-N7100)
Baseband : NG4
ROM : Dr. Ketan V9

 




My Facebook page | My XDA Contributions



Previous Devices -

Pandigital Supernova Tablet
Samsung Galaxy Ace
Samsung Galaxy Mini
 
gabrielking9
Old
#6  
Senior Member
Thanks Meter 398
Posts: 2,240
Join Date: Feb 2012
Location: Recife
Default Re: [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Any tuto for Mac? :s Dunno how to access use folder to put the apktool in mac

Sent from my GT-S5570 using xda app-developers app
Press thanks if i helped you.

Device
Samsung Galaxy Mini S5570B - DEAD
Motorola Razr D1 XT916 - LIVE
 
hsay
Old
#7  
hsay's Avatar
Senior Member
Thanks Meter 565
Posts: 1,497
Join Date: May 2012
Location: pune
Default Re: [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Quote:
Originally Posted by The Alchemist View Post
yea its easier but i prefer apktool simply...
You really rock! You wrote a while awesome thread just cause one Guy mentioned he couldn't get it up and running and he didn't even ask for help.... you are awesome..,

Sent from my GT-S5570 using Tapatalk 2
Don't thank me..........but do give respect if I deserve it........
MY WORKS:

1.AOXP mod for AOSP by Paul.L
2.UBER SPB P+
3.Windows phone 7 theme cm7/cmx
4.Windows phone 7 ROM (cmx)
MY BLOG - BE A DEV
The Following 2 Users Say Thank You to hsay For This Useful Post: [ Click to Expand ]
 
gabrielking9
Old
#8  
Senior Member
Thanks Meter 398
Posts: 2,240
Join Date: Feb 2012
Location: Recife
Default Re: [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Big thanks to this Guy named Alchemist will try install windows here and try It

Sent from my GT-S5570 using xda app-developers app
Press thanks if i helped you.

Device
Samsung Galaxy Mini S5570B - DEAD
Motorola Razr D1 XT916 - LIVE
 
A_U
Old
#9  
Recognized Contributor / Themer - OP
Thanks Meter 4,568
Posts: 3,223
Join Date: Jun 2012
Quote:
Originally Posted by gabrielking9 View Post
Any tuto for Mac? :s Dunno how to access use folder to put the apktool in mac

Sent from my GT-S5570 using xda app-developers app
will write that first thing tomo morning...but why not dual boot windows ? can that be done in mac ? i dont know since i never used mac...
Samsung Galaxy Note 2 (GT-N7100)
Baseband : NG4
ROM : Dr. Ketan V9

 




My Facebook page | My XDA Contributions



Previous Devices -

Pandigital Supernova Tablet
Samsung Galaxy Ace
Samsung Galaxy Mini
 
gabrielking9
Old
#10  
Senior Member
Thanks Meter 398
Posts: 2,240
Join Date: Feb 2012
Location: Recife
Default Re: [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Quote:
Originally Posted by The Alchemist View Post
will write that first thing tomo morning...but why not dual boot windows ? can that be done in mac ? i dont know since i never used mac...
Yeah it can but my father... but I can with parallels app without him discover I just need found one cracked :x

Sent from my GT-S5570 using xda app-developers app
Press thanks if i helped you.

Device
Samsung Galaxy Mini S5570B - DEAD
Motorola Razr D1 XT916 - LIVE

Tags
apktool, guide, how-to, linux, sign
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes