5,814,633 Members 53,469 Now Online
XDA Developers Android and Mobile Development Forum

[How To]: Decompile / Compile .APK

Tip us?
 
idroid84
Old
#1  
idroid84's Avatar
Senior Member - OP
Thanks Meter 12
Posts: 498
Join Date: Mar 2010
Location: UK
Default [How To]: Decompile / Compile .APK

Source Found

Brut.all of XDA has released the program APKtool which make the process of editing any APK file much easier, especially XML editing. Before you had to use a few different programs (Smali, hex editor, etc) to do the same thing. A future release is going to have the decompiler dump into an easy to import into Javabeans/Eclipse format.. so nice

Program and Usage link;
APKTool 1.2

Setup;
Before you start, download from the link above both the apktool-1.2.0.tar.bz2 and apktool-install-windows-2.2_r01-1.tar.bz2 and extract them to your windows folder.

Usage;
Decoding APKs;
Code:
apktool d <file.apk> <directory to output to>
Compiling APKs*;
Code:
apktool b <directory of decoded apk>
*The compiled apk will be saved to the sub directory "dist", which is in what ever directory you choose to compile.

Output structure;
Smali directory - The output of classes.dex, the code to the apk
Res directory - Your resources, the images and layout/structure xmls
Lib directory - Shared library files
Dist directory - The apk output of the "apktool b" command, if you didn't run it you won't have it.
Build directory - The compiled output of the "apktool b" command, like what you would see if you just extracted an apk file with 7zip. If you didn't run it you won't have it.

General info;
Once you have your edited apk from the Dist directory you'll need to sign it. I use Dave Da illest 1 of XDA's modified script for signing. Just place your apk, this should be the only apk in this folder, in the same folder that you extracted the auto-signer to and execute sign.bat. The script will output your_app_signed.apk, which is your signed and ready to load on your phone apk.
If you'd like to decompile/compile an apk file that doesn't have a classes.dex, like framework-res.apk, just place any classes.dex into the apk and it will decompile. If you don't do this apktool will through up an error. Just remember to pull the classes.dex out before you sign it.

Videos;
Editing an Apk file with APKTool;
http://www.youtube.com/watch?v=XXgYVHTcl6c

Editing a Jar file with APKtool;
http://www.youtube.com/watch?v=VAekeWiqHcY

Why?;
Localization / Translation
Themeing
Adding in features or taking them out
Impressing friends and family, lol
etc..

Issues;
I noticed that while the new version 1.2 works great on the framework-res.apk file, it seems to have issues with other System/app files like Settings.apk,Phone.apk, etc. For these files use version 1.1.1.

Hopefully this is helpful, I tend to ramble.
-Ften @ sdx-developers.com
The Following 6 Users Say Thank You to idroid84 For This Useful Post: [ Click to Expand ]
 
shokkapic
Old
#2  
shokkapic's Avatar
Senior Member
Thanks Meter 4
Posts: 176
Join Date: Mar 2010
Location: Lisbon
http://forum.xda-developers.com/forumdisplay.php?f=613

Post it here too, mate.
 
idroid84
Old
(Last edited by idroid84; 21st June 2010 at 03:07 PM.)
#3  
idroid84's Avatar
Senior Member - OP
Thanks Meter 12
Posts: 498
Join Date: Mar 2010
Location: UK
Quote:
Originally Posted by shokkapic View Post
Will do, not having a good time at the moment as I can't seem to edit launcher.apk with this tool. Not sure why. basically I decompile, edit then compile but having issues when transferring it back to the phone.

EDIT: I just get a black screen when trying the new modified .apk file.
The Following User Says Thank You to idroid84 For This Useful Post: [ Click to Expand ]
 
Brut.all
Old
#4  
Recognized Developer
Thanks Meter 335
Posts: 1,467
Join Date: Jul 2009
Why to create new threads, if apktool has its official thread here :)

http://forum.xda-developers.com/showthread.php?t=640592

Quote:
Originally Posted by andrewb84uk View Post
Will do, not having a good time at the moment as I can't seem to edit launcher.apk with this tool. Not sure why. basically I decompile, edit then compile but having issues when transferring it back to the phone.

EDIT: I just get a black screen when trying the new modified .apk file.
Do you get any errors in logcat?
G+ | apktool | Ingress broot mod | Brut Google Maps (dead)

If you like me you can buy me a droidburger!
 
idroid84
Old
(Last edited by idroid84; 21st June 2010 at 03:55 PM.)
#5  
idroid84's Avatar
Senior Member - OP
Thanks Meter 12
Posts: 498
Join Date: Mar 2010
Location: UK
Quote:
Originally Posted by Brut.all View Post
Why to create new threads, if apktool has its official thread here :)

http://forum.xda-developers.com/showthread.php?t=640592



Do you get any errors in logcat?
I could not find it anywhere else and I did do searches for hours Brilliant tool!

See Attachment, I think it's this line
Code:
E/PackageManager(  138): Package com.android.launcher signatures do not match the previously installed version; ignoring!
However, not sure how to fix it.
Attached Files
File Type: txt logfile.txt - [Click for QR Code] (64.5 KB, 100 views)
 
shokkapic
Old
#6  
shokkapic's Avatar
Senior Member
Thanks Meter 4
Posts: 176
Join Date: Mar 2010
Location: Lisbon
Quote:
Originally Posted by andrewb84uk View Post
I could not find it anywhere else and I did do searches for hours Brilliant tool!

See Attachment, I think it's this line
Code:
E/PackageManager(  138): Package com.android.launcher signatures do not match the previously installed version; ignoring!
However, not sure how to fix it.

Not an expert. But try to uninstall the previous launcher, before installing that one.
 
idroid84
Old
(Last edited by idroid84; 21st June 2010 at 04:06 PM.)
#7  
idroid84's Avatar
Senior Member - OP
Thanks Meter 12
Posts: 498
Join Date: Mar 2010
Location: UK
Quote:
Originally Posted by shokkapic View Post
Not an expert. But try to uninstall the previous launcher, before installing that one.
Will try it.

EDIT: Nope, uninstalled re-installed, still black screen.
 
Brut.all
Old
#8  
Recognized Developer
Thanks Meter 335
Posts: 1,467
Join Date: Jul 2009
Quote:
Originally Posted by andrewb84uk View Post
I could not find it anywhere else and I did do searches for hours Brilliant tool!

See Attachment, I think it's this line
Code:
E/PackageManager(  138): Package com.android.launcher signatures do not match the previously installed version; ignoring!
However, not sure how to fix it.
I think you can't install Launcher just like that, because it's system app. You should do it through update.zip file.

Try to not use apktool, but just unpack Launcher.apk, remove META-INF dir, zip it back, sign and install. If you will get similar problems, then they can't be related to apktool (because you didn't even use it), but to something else.
G+ | apktool | Ingress broot mod | Brut Google Maps (dead)

If you like me you can buy me a droidburger!
 
idroid84
Old
(Last edited by idroid84; 21st June 2010 at 04:29 PM.)
#9  
idroid84's Avatar
Senior Member - OP
Thanks Meter 12
Posts: 498
Join Date: Mar 2010
Location: UK
Quote:
Originally Posted by Brut.all View Post
I think you can't install Launcher just like that, because it's system app. You should do it through update.zip file.

Try to not use apktool, but just unpack Launcher.apk, remove META-INF dir, zip it back, sign and install. If you will get similar problems, then they can't be related to apktool (because you didn't even use it), but to something else.
If I unzip it, remove META-INF dir, zip it back, sign + install and it works fine. It doesn't work when I edit 1 file by decompiling and compiling, sign, upload it fails but it also fails using APKManager.

EDIT: I have also tried using notepad++ / notepad to edit the xml both to the same issue.
 
Brut.all
Old
#10  
Recognized Developer
Thanks Meter 335
Posts: 1,467
Join Date: Jul 2009
Err... you know, your problem is for sure related to signing/installation and not to apktool. Key error line is here:

Quote:
E/PackageManager( 138): Package com.android.launcher signatures do not match the previously installed version; ignoring!
Quote:
Originally Posted by andrewb84uk View Post
If I unzip it, remove META-INF dir, zip it back, sign + install and it works fine. It doesn't work when I edit 1 file by decompiling and compiling, sign, upload it fails but it also fails using APKManager.
Could you explain, how is it possible, that you can properly sign rezipped apk, but you can't reapktoold' one? If you get signing issues, then this is totally irrelevant what apktool does. All files could be random binary strings as well cause they aren't even read.
G+ | apktool | Ingress broot mod | Brut Google Maps (dead)

If you like me you can buy me a droidburger!

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Google Play Store to Show Price Ranges for In-App Purchases

Google recently announced a change to Google Play Store policy that requires … more

XDA Xposed Tuesday: How to Shut Up Your Phone – XDA Developer TV

So many different applications want to send us notifications that … more

Add Some Power to First Generation Snapdragon CPUs

Some older devices still remain very popular. Phones like theHTC Desire, Sony Ericsson … more

Android M Mentions Spotted in Android Code Review

While we are still waiting for Android L to be officially released, the first mentions of … more