FORUMS
Remove All Ads from XDA

[HOW-TO][29/MAR] How to setup APKTool & Decompile, Recomile, Sign, and Zipalign APKs

7,537 posts
Thanks Meter: 5,742
 
Post Reply Email Thread
Decompile, Recompile, Sign and Zipalign APKs

Since there aren't many tutorials out there on how to decompile, recompile, sign and zipalign the framework-res.apk, or other APK files, I decided to create one myself

Decompiling, editing, recompiling and signing It can yield a number of results, for example, you can edit the values, add custom images, fix some issues, or just go on an adventure

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[WHAT YOU NEED]


1) A computer

2) The APK you want to edit

3) Latest Java Development Kit (JDK) (Download and Install with default settings http://www.java.com/en/download/index.jsp)

4) Some resource files, which I have bundled into on convenient zip, found here.

5) The Framework-res.apk from /system/framework
- In the case of it being an APK from an HTC based ROM, you will also need the com.htc,resources.apk, found in the same directory
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[STEPS]


- Initial Setup

- First download the zip from above, and extract the files, into C:\Android\APK
- Then, install the JDK from the link above, to the default location
- Then, go to Start, search for 'Environment,' and choose 'Edit Environment Variables for your Account.'
- Now, edit 'PATH,' and 'CLASSPATH.' (If you don't have them, just add them, and name them PATH and CLASSPATH)
- - For PATH, give this as the Variable Value: "C:\Program Files\Java\jdkXXX\bin;" (Without Quotes)(XXX is the JDK version you have)
- - For CLASSPATH, give this as the Variable Value: "C:\Program Files\Java\jdkXXX\jre\lib;" (Without Quotes)(XXX is the JDK version you have)
- Install the Framework:

- Now, move the framework-res.apk, and com.htc.resources.apk (If HTC), to C:\Android\APK
- Press shift, and right click in the folder, and open a command prompt window from the dropdown
- - Type in: "Apktool if framework-res.apk" (Without Quotes) And Press Enter
- - If it is an HTC ROM, Type in: "Apktool if com.htc.resources.apk" (Without Quotes) And Press Enter
- If this goes successfully, you can remove these two APKs from the folder
* NOTE: Everything above was ONE TIME ONLY *

- Decompiling the APK

- Now, copy the APK that you want to decmopile, to C:\Android\APK
- Open a command prompt window there
- Type in "Apktool d xxx.apk" (Without Quotes, and replace xxx with the APK name)
- Once this is done successfully, you will have a folder with the APK name in C:\Android\APK
- You can now make any edits you like
- Recompiling the APK

- Once you're done editing, go back to C:\Android\APK
- Open a command prompt window, and type in "Apktool b xxx"
(Without Quotes, and xxx is the name of the folder where the APK was extracted)
- Once this is done, the new APK can be found in C:\Android\APK\xxx\dist (xxx is name of folder where you extracted the APK)
- Signing, and Zipaligning

- Now, there are two ways to do this.
- - Either you install DSIXDA's kitchen, from here, and use that to Sign, and Zipalign
- - Or, you send me the APK, and I'll do it for you

* NOTE: Always Sign, THEN Zipalign *
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[CREDITS]


1• Mwilky for teaching me all this
2• Floatshow for initial recompiling instructions
3• Fisha21 for helping out

The Following 89 Users Say Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
 
 
30th July 2012, 08:20 PM |#2  
Senior Member
Flag Petah Tiqwa
Thanks Meter: 253
 
Donate to Me
More
And how about to recompile it back ?
What are the steps ?

Sent from my HOX
30th July 2012, 08:39 PM |#3  
theDroidfanatic's Avatar
OP Senior Member
Flag Jeddah
Thanks Meter: 5,742
 
More
Quote:
Originally Posted by 1immortal

And how about to recompile it back ?
What are the steps ?

Sent from my HOX

Hmm, for that, we have to use 'aapt.exe' I will post a tutorial for it soon

download it here meanwhile
The Following 3 Users Say Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
30th July 2012, 10:55 PM |#4  
theDroidfanatic's Avatar
OP Senior Member
Flag Jeddah
Thanks Meter: 5,742
 
More
Quote:
Originally Posted by 1immortal

And how about to recompile it back ?
What are the steps ?

Sent from my HOX

Added recompiling steps

Sent from my HTC One X using xda premium
The Following 3 Users Say Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
30th July 2012, 11:29 PM |#5  
Mr.Mefisto's Avatar
Senior Member
rskmania
Thanks Meter: 3,100
 
Donate to Me
More
Thumbs up
Nice guide! Thanks OP!
The Following 2 Users Say Thank You to Mr.Mefisto For This Useful Post: [ View ] Gift Mr.Mefisto Ad-Free
30th July 2012, 11:40 PM |#6  
theDroidfanatic's Avatar
OP Senior Member
Flag Jeddah
Thanks Meter: 5,742
 
More
Quote:
Originally Posted by Mr.Mefisto

Nice guide! Thanks OP!

No problemo

Sent from my HTC One X using xda premium
The Following 2 Users Say Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
4th August 2012, 08:51 PM |#7  
Senior Member
Thanks Meter: 23
 
More
Nice guide! Question is do you have to sign system APKs? (Such as framework-rés.apk or SystemUI.apk)

Sent from my HTC One X using xda premium
The Following 2 Users Say Thank You to Mazzstrikers For This Useful Post: [ View ] Gift Mazzstrikers Ad-Free
4th August 2012, 11:07 PM |#8  
theDroidfanatic's Avatar
OP Senior Member
Flag Jeddah
Thanks Meter: 5,742
 
More
Yes we do, use SignAPK

Sent from my HTC One X using xda premium
The Following 2 Users Say Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
12th August 2012, 07:07 PM |#9  
Senior Member
Thanks Meter: 55
 
More
when I'm trying to recompile, I get this:

Code:
D:\Decompiling>java -jar apktool.jar b framework-res framework-res.apk
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
D:\Decompiling\framework-res\res\values\layouts.xml:3: error: Found tag layout w
here item is expected
D:\Decompiling\framework-res\res\values\raws.xml:3: error: Found tag raw where i
tem is expected
D:\Decompiling\framework-res\res\values\public.xml:6943: error: Public symbol la
yout/htc_list_item_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6944: error: Public symbol la
yout/htc_list_item_2text_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6945: error: Public symbol la
yout/htc_list_item_image_2text_image_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6946: error: Public symbol la
yout/htc_list_item_imageicon_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6947: error: Public symbol la
yout/htc_list_item_imageicon_text declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6948: error: Public symbol la
yout/htc_list_item_separator declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6949: error: Public symbol la
yout/keyguard_screen_device_unlock declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6950: error: Public symbol la
yout/pin_keyboard declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:7151: error: Public symbol ra
w/fallbackring_htc declared here is not defined.
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutExce
ption: could not exec command: [aapt, p, -F, C:\Users\WiZARD\AppData\Local\Temp\
APKTOOL1215629564114721126.tmp, -x, -S, D:\Decompiling\framework-res\res, -M, D:
\Decompiling\framework-res\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:193)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:301)
        at brut.androlib.Androlib.buildResources(Androlib.java:248)
        at brut.androlib.Androlib.build(Androlib.java:171)
        at brut.androlib.Androlib.build(Androlib.java:154)
        at brut.apktool.Main.cmdBuild(Main.java:182)
        at brut.apktool.Main.main(Main.java:67)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, C:\U
sers\WiZARD\AppData\Local\Temp\APKTOOL1215629564114721126.tmp, -x, -S, D:\Decomp
iling\framework-res\res, -M, D:\Decompiling\framework-res\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:83)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:191)
        ... 6 more
what should I do?
12th August 2012, 08:28 PM |#10  
theDroidfanatic's Avatar
OP Senior Member
Flag Jeddah
Thanks Meter: 5,742
 
More
Quote:
Originally Posted by WiZARD7

when I'm trying to recompile, I get this:

Code:
D:\Decompiling>java -jar apktool.jar b framework-res framework-res.apk
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
D:\Decompiling\framework-res\res\values\layouts.xml:3: error: Found tag layout w
here item is expected
D:\Decompiling\framework-res\res\values\raws.xml:3: error: Found tag raw where i
tem is expected
D:\Decompiling\framework-res\res\values\public.xml:6943: error: Public symbol la
yout/htc_list_item_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6944: error: Public symbol la
yout/htc_list_item_2text_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6945: error: Public symbol la
yout/htc_list_item_image_2text_image_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6946: error: Public symbol la
yout/htc_list_item_imageicon_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6947: error: Public symbol la
yout/htc_list_item_imageicon_text declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6948: error: Public symbol la
yout/htc_list_item_separator declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6949: error: Public symbol la
yout/keyguard_screen_device_unlock declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6950: error: Public symbol la
yout/pin_keyboard declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:7151: error: Public symbol ra
w/fallbackring_htc declared here is not defined.
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutExce
ption: could not exec command: [aapt, p, -F, C:\Users\WiZARD\AppData\Local\Temp\
APKTOOL1215629564114721126.tmp, -x, -S, D:\Decompiling\framework-res\res, -M, D:
\Decompiling\framework-res\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:193)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:301)
        at brut.androlib.Androlib.buildResources(Androlib.java:248)
        at brut.androlib.Androlib.build(Androlib.java:171)
        at brut.androlib.Androlib.build(Androlib.java:154)
        at brut.apktool.Main.cmdBuild(Main.java:182)
        at brut.apktool.Main.main(Main.java:67)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, C:\U
sers\WiZARD\AppData\Local\Temp\APKTOOL1215629564114721126.tmp, -x, -S, D:\Decomp
iling\framework-res\res, -M, D:\Decompiling\framework-res\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:83)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:191)
        ... 6 more
what should I do?

Reading that, I seriously have no idea :S Im no expert, just know basics, so I wrote this tutorial. Try Google? Really sorry :/

Sent from my HTC One X using xda premium
The Following User Says Thank You to theDroidfanatic For This Useful Post: [ View ] Gift theDroidfanatic Ad-Free
13th August 2012, 06:29 PM |#11  
fisha21's Avatar
Senior Member
Thanks Meter: 4,304
 
More
There is a problem with older versions of APKtool, in that they break the formatting of some of the XML tags in framework-res.apk, which is why your recompiling fails.

Check this thread for how to fix it: http://forum.xda-developers.com/show....php?t=1601511

However, I think the newest version of apktool.jar fixes this for us. You can download this version at ibotpeaches' thread:

http://forum.xda-developers.com/show...php?p=28366939

As well as the newest version of apktool.jar, you also need the updated aapt.exe, which can you grab here:

http://forum.xda-developers.com/show...&postcount=157



Quote:
Originally Posted by WiZARD7

when I'm trying to recompile, I get this:

Code:
D:\Decompiling>java -jar apktool.jar b framework-res framework-res.apk
W: Could not find sources
I: Checking whether resources has changed...
I: Building resources...
D:\Decompiling\framework-res\res\values\layouts.xml:3: error: Found tag layout w
here item is expected
D:\Decompiling\framework-res\res\values\raws.xml:3: error: Found tag raw where i
tem is expected
D:\Decompiling\framework-res\res\values\public.xml:6943: error: Public symbol la
yout/htc_list_item_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6944: error: Public symbol la
yout/htc_list_item_2text_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6945: error: Public symbol la
yout/htc_list_item_image_2text_image_bright declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6946: error: Public symbol la
yout/htc_list_item_imageicon_2text_2stamp declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6947: error: Public symbol la
yout/htc_list_item_imageicon_text declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6948: error: Public symbol la
yout/htc_list_item_separator declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6949: error: Public symbol la
yout/keyguard_screen_device_unlock declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:6950: error: Public symbol la
yout/pin_keyboard declared here is not defined.
D:\Decompiling\framework-res\res\values\public.xml:7151: error: Public symbol ra
w/fallbackring_htc declared here is not defined.
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutExce
ption: could not exec command: [aapt, p, -F, C:\Users\WiZARD\AppData\Local\Temp\
APKTOOL1215629564114721126.tmp, -x, -S, D:\Decompiling\framework-res\res, -M, D:
\Decompiling\framework-res\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:193)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:301)
        at brut.androlib.Androlib.buildResources(Androlib.java:248)
        at brut.androlib.Androlib.build(Androlib.java:171)
        at brut.androlib.Androlib.build(Androlib.java:154)
        at brut.apktool.Main.cmdBuild(Main.java:182)
        at brut.apktool.Main.main(Main.java:67)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, C:\U
sers\WiZARD\AppData\Local\Temp\APKTOOL1215629564114721126.tmp, -x, -S, D:\Decomp
iling\framework-res\res, -M, D:\Decompiling\framework-res\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:83)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:191)
        ... 6 more
what should I do?

The Following 3 Users Say Thank You to fisha21 For This Useful Post: [ View ] Gift fisha21 Ad-Free
Post Reply Subscribe to Thread

Tags
apk, apktool, decompile, framework

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes