[How To]: Decompile / Compile .APK

Search This thread

idroid84

Senior Member
Mar 12, 2010
513
12
UK
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
 

idroid84

Senior Member
Mar 12, 2010
513
12
UK
Last edited:
  • Like
Reactions: Djole-97

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Why to create new threads, if apktool has its official thread here :)

http://xdaforums.com/showthread.php?t=640592

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. :mad:

EDIT: I just get a black screen when trying the new modified .apk file. :mad:

Do you get any errors in logcat?
 

idroid84

Senior Member
Mar 12, 2010
513
12
UK
Why to create new threads, if apktool has its official thread here :)

http://xdaforums.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.
 

Attachments

  • logfile.txt
    64.5 KB · Views: 120
Last edited:

shokkapic

Senior Member
Mar 3, 2010
191
5
Lisbon
www.xda-developers.com
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. :)
 

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
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.
 

idroid84

Senior Member
Mar 12, 2010
513
12
UK
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:

Brut.all

Inactive Recognized Developer
Jul 27, 2009
1,471
353
Err... you know, your problem is for sure related to signing/installation and not to apktool. Key error line is here:

E/PackageManager( 138): Package com.android.launcher signatures do not match the previously installed version; ignoring!

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.
 

lightyear420

Senior Member
Oct 16, 2010
478
67
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.

Thank you soooo much!!! It took me hours of searching to find this post and once I did, I had my apk decompressed in under a minute!!! You da man :D
 

noiofnine

Senior Member
Jan 20, 2011
109
7
Hey guys... really trying to theme for the first time with xml files.
I have done modifying of png which are easy, but just lenghty and detailed.
So now that Gingerbread is out, some of the items have been moved to the xml files.

indeterminate was from 4 and now down to 3. but I want to increase to 8 to mimic honeycomb. Also the progress horizontal was once a png reference file now its in the systemui.apk xml too.

Anyhow short version.... anytime i edit more then 1 line at a time after decompiling, when trying to say it will ask to save as text.
Whats the best file editor for xml? or recommendations.
 

noiofnine

Senior Member
Jan 20, 2011
109
7
Yeah I have been using that do and any time I compile and flash it just gives me boot loop.

Question about proper importing to eclips.
Whenever I just flat out decompile ... do my modification, go to recompile, it get errors. In apktool and apkmanager.

Should I extract the resource file and class dex out and then decompile. Cus when I have the resource file in the same directory....at least last nights attempt, apktool finale didn't give me an error and compiled.

I've done a decompile just from apk and imported to eclips and when I try to run, gives error.... "no style availiable" or something like that


Sent from my Droid using XDA App
 

highhacker

Senior Member
fixing a broken abondon market apk

Could someone fix this app VirginmobileMinuitechecker . I think i found the problem . Virgin Mobile updated there site from logon www1 to www2 . I edited it from the open source and zipped it back up but i cannot get this compile program to run at all . here is the zip master . I made several attempts emailing jay goel but he his MIA .. the app will no longer log in because of the VM website recent changes . TIA

EDIT ,, NEVER MIND . i got it working and fixed that app . works like a charm now :) pretty good being i don't code for a living.. if you don't mind i posted the fixed app . you may move or delete if it is not proper . thank you for the tutorial .
 

Attachments

  • VirginMobileMinutesChecker-master.zip
    464 KB · Views: 12
  • VirginMobileMinutesChecker-signed.apk
    101.1 KB · Views: 7
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    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
    1

    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. :mad:

    EDIT: I just get a black screen when trying the new modified .apk file. :mad: