Post Reply

[How To]: Decompile / Compile .APK

OP idroid84

21st June 2010, 01:27 PM   |  #1  
idroid84's Avatar
OP Senior Member
Flag UK
Thanks Meter: 12
 
498 posts
Join Date:Joined: Mar 2010
More
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: [ View ]
21st June 2010, 02:32 PM   |  #2  
shokkapic's Avatar
Senior Member
Flag Lisbon
Thanks Meter: 4
 
176 posts
Join Date:Joined: Mar 2010
More
http://forum.xda-developers.com/forumdisplay.php?f=613

Post it here too, mate.
21st June 2010, 02:38 PM   |  #3  
idroid84's Avatar
OP Senior Member
Flag UK
Thanks Meter: 12
 
498 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by shokkapic

http://forum.xda-developers.com/forumdisplay.php?f=613

Post it here too, mate.

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.
Last edited by idroid84; 21st June 2010 at 03:07 PM.
The Following User Says Thank You to idroid84 For This Useful Post: [ View ]
21st June 2010, 03:43 PM   |  #4  
Recognized Developer
Thanks Meter: 336
 
1,467 posts
Join Date:Joined: Jul 2009
More
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

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?
21st June 2010, 03:46 PM   |  #5  
idroid84's Avatar
OP Senior Member
Flag UK
Thanks Meter: 12
 
498 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by Brut.all

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)
Last edited by idroid84; 21st June 2010 at 03:55 PM.
21st June 2010, 03:58 PM   |  #6  
shokkapic's Avatar
Senior Member
Flag Lisbon
Thanks Meter: 4
 
176 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by andrewb84uk

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.
21st June 2010, 04:02 PM   |  #7  
idroid84's Avatar
OP Senior Member
Flag UK
Thanks Meter: 12
 
498 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by shokkapic

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.
Last edited by idroid84; 21st June 2010 at 04:06 PM.
21st June 2010, 04:06 PM   |  #8  
Recognized Developer
Thanks Meter: 336
 
1,467 posts
Join Date:Joined: Jul 2009
More
Quote:
Originally Posted by andrewb84uk

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.
21st June 2010, 04:14 PM   |  #9  
idroid84's Avatar
OP Senior Member
Flag UK
Thanks Meter: 12
 
498 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by Brut.all

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.
Last edited by idroid84; 21st June 2010 at 04:29 PM.
22nd June 2010, 10:32 AM   |  #10  
Recognized Developer
Thanks Meter: 336
 
1,467 posts
Join Date:Joined: Jul 2009
More
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

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.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes