New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
Hero
Old
(Last edited by Hero; 28th May 2013 at 11:50 PM.)
#1  
Hero's Avatar
Recognized Developer - OP
Thanks Meter 4070
Posts: 1,143
Join Date: Oct 2010
Location: San Diego

 
DONATE TO ME
Tutorial [HOW-TO] Decompile ICS and above apk and jar files MANUALLY

With the number of ICS ROMs that are popping out, I imagine the majority of people are spending their time on ICS rather than Gingerbread or Froyo. With that in mind, here's a little guide on how to decompile ICS .apk and .jar files (such as the troublesome SystemUI.apk) with ease so that you can mod them to your heart's content. I assume this method will work for other versions of Android as well. Just so we understand each other, this just helps you decompile the classes.dex. If you want to decompile an entire app or jar file there are other guides for that.

NOTE: We will NOT be using ApkTool, Apk Manager, or StudioAndroid to do this. Mainly because I have had trouble in the past using those applications to decompile certain files. So, here is an ALL MANUAL way.

What you need:
  • Deodexed .apk/.jar file
  • smali.jar
  • baksmali.jar
  • 7zip or Betterzip (whether you are on Mac, Linux, or Windows)
  • terminal/cmd (depending on what you're running)

You can get the smali.jar and baksmali.jar files from here: http://code.google.com/p/smali/downloads/list

Download these files:
Code:
baksmali-1.3.3.jar
smali-1.3.3.jar
and rename them to:
Code:
baksmali.jar
smali.jar
Now that you have both files, place them somewhere you'll remember (like a folder on your Desktop). For the purposes of this guide, my files will be in .../Desktop/ICS

Ready? Okay, here we go.

  1. Open up your desired ICS .apk or .jar file with 7zip or Betterzip and extract the classes.dex and move it into the directory where you have baksmali.jar and smali.jar (For example, I move the classes.dex file to .../Desktop/ICS)
  2. Open up terminal or cmd
  3. cd to your directory
    Example:
    Code:
    cd .../Desktop/ICS
  4. Type the following:
    Code:
    java -jar baksmali.jar -o classout/ classes.dex
    This will decompile the classes.dex file and create a folder inside .../Desktop/ICS called classout where all of your smali files will be located.
  5. Go into the classout folder and make your smali edits
  6. Compile your classout folder into new-classes.dex by typing this into terminal:
    Code:
    java -Xmx512M -jar smali.jar classout/ -o new-classes.dex
  7. Rename new-classes.dex to classes.dex
  8. Take your newly compiled classes.dex and put it into your ICS .apk or .jar using 7zip or Betterzip
  9. Profit

Have fun
The Following 43 Users Say Thank You to Hero For This Useful Post: [ Click to Expand ]
 
kzoodroid
Old
#2  
kzoodroid's Avatar
Senior Member
Thanks Meter 219
Posts: 1,173
Join Date: Jun 2010
Location: Kalamazoo
Nice to have a write up on this in the Inc forums instead of having to hunt it down all the time. I've found it best to use smali and baksmali too, the apk aps were just too flaky for me.
Nexus 4 - Stock, Rooted, CWM. Samsung Galaxy Tab 7 Plus - Stock, Rooted
The Following User Says Thank You to kzoodroid For This Useful Post: [ Click to Expand ]
 
Hero
Old
(Last edited by Hero; 8th July 2012 at 08:29 AM.)
#3  
Hero's Avatar
Recognized Developer - OP
Thanks Meter 4070
Posts: 1,143
Join Date: Oct 2010
Location: San Diego

 
DONATE TO ME
Quote:
Originally Posted by kzoodroid View Post
Nice to have a write up on this in the Inc forums instead of having to hunt it down all the time. I've found it best to use smali and baksmali too, the apk aps were just too flaky for me.
Yeah I've had similar experiences as well. This method was the only one that worked flawlessly for me. Hopefully it works for you and everyone else who needs to modify ICS files.
 
kzoodroid
Old
#4  
kzoodroid's Avatar
Senior Member
Thanks Meter 219
Posts: 1,173
Join Date: Jun 2010
Location: Kalamazoo
I've used it in GB to do some of the modifications to the status bar, like hide the clock. Took the better part of a day googling to actually find a write up on how to use baksmali and smali as I couldn't get apkTool or apkManager to decompile or compile classes.dex properly. Now I know where to find the instructions when I need them again.
Nexus 4 - Stock, Rooted, CWM. Samsung Galaxy Tab 7 Plus - Stock, Rooted
 
cowsquad
Old
#5  
cowsquad's Avatar
Senior Member
Thanks Meter 212
Posts: 948
Join Date: Aug 2009
Location: Portland, Oregon

 
DONATE TO ME
thank you for this nice write up. It did really help me
 
T-Macgnolia
Old
#6  
T-Macgnolia's Avatar
Recognized Contributor
Thanks Meter 1552
Posts: 3,498
Join Date: Sep 2010
Location: Shannon, Ms.

 
DONATE TO ME
Man you are just awesome for posting this, I have been googling how to decompile and recompile .apk's and .jar's for a couple of days and nothing has worked. This worked great the first time around and was very simple to follow. I just hope that once I am done making my editsI do not have any troubles re compiling the .jar I am working with lol.

You know it is so ironic that I found your guide here on XDA. It seems like everytime i want to learn how to do something like this I can google all day without much success on finding something that works. But when I do find something that works around 90% to 95% of the time it is here on XDA. You have got to love XDA...

New to XDA? Please have a read here and here, they are here to help you.
XDA Search Video
S-off explained
Guide on HTC HD2
4EXT Themes, Splash screens, and Bootanimation By T-Macgnolia
XDA-BLOG Writer
RegawMOD Bootloader Customizer for Sensation

Current daily device= Samsung Galaxy Note 2
ROM=TMOUS Stock Multi Window update not rooted
Other devices=TMOUS HTC Sensation 4G,TMOUS HTC HD2 , Acer Iconia A500

The Following 2 Users Say Thank You to T-Macgnolia For This Useful Post: [ Click to Expand ]
 
Hero
Old
#7  
Hero's Avatar
Recognized Developer - OP
Thanks Meter 4070
Posts: 1,143
Join Date: Oct 2010
Location: San Diego

 
DONATE TO ME
Quote:
Originally Posted by T-Macgnolia View Post
Man you are just awesome for posting this, I have been googling how to decompile and recompile .apk's and .jar's for a couple of days and nothing has worked. This worked great the first time around and was very simple to follow. I just hope that once I am done making my editsI do not have any troubles re compiling the .jar I am working with lol.

You know it is so ironic that I found your guide here on XDA. It seems like everytime i want to learn how to do something like this I can google all day without much success on finding something that works. But when I do find something that works around 90% to 95% of the time it is here on XDA. You have got to love XDA...
Yeah XDA does seem to be the go-to place for everything lol. Glad to know it worked for you
 
kong
Old
#8  
kong's Avatar
Senior Member
Thanks Meter 652
Posts: 951
Join Date: Jan 2012
Note that you still need apktool in order to decompile/recompile XMLs and PNGs in apk files.
The Following User Says Thank You to kong For This Useful Post: [ Click to Expand ]
 
SifJar
Old
#9  
Senior Member
Thanks Meter 224
Posts: 544
Join Date: Jul 2009
Quote:
Originally Posted by kong View Post
Note that you still need apktool in order to decompile/recompile XMLs and PNGs in apk files.
Are there no other standalone command line tools for those tasks?
 
jcejohnson
Old
#10  
jcejohnson's Avatar
Member
Thanks Meter 6
Posts: 65
Join Date: Jul 2012
Location: Atlanta
Quote:
Originally Posted by SifJar View Post
Are there no other standalone command line tools for those tasks?
I would like to know that as well...