Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
itiskonrad
Old
(Last edited by itiskonrad; 29th January 2012 at 02:10 PM.)
#1  
Senior Member - OP
Thanks Meter 175
Posts: 238
Join Date: Dec 2009
Default TUTORIAL - decompiling/editing XML

**This is for system apk's, not for market ones. To modify apps you've downloaded and installed, you will need a program like the fantastic Apk Manager, since non-system apps are signed and have to be resigned after getting messed with**

*MY TYPICAL DISCLAIMER!*
I AM NOT A DEV! I just like tinkering with this phone because I'm overall an extremely picky and obsessive person. I have no prior android experience (besides a little tinkering with my X10), and am in NO way an expert. But since I know how to mess with my phone a little bit and I've been asked to share, I will =) But follow these instructions at your own risk! I am not responsible for the untimely death of your phone, so please be cautious and careful, and if you have any questions about any step, before you try it, ask me or someone who knows! I don't want the blood of your dead phone on my hands! It's Christmas, after all! =)

These instructions are for Windows computers. Sorry, I'm just not familiar with mac or linux. =(

***Editing XML's***

So you want to modify something a little more complicated than just a PNG- there's something there you want gone, something too big or small, and you want to modify an XML. Here's what you need for starters:

7zip for your computer
Root explorer for your phone
apktool and apktool-install-windows for your computer from here
-Install it to your computer, as described in the link. (Just unpacking the items into c:/Windows is easiest)
Hex editor for your computer (I really like Notepad++)

For an example, I will be using the HORRIBLE yellow pages infiltration of the LG Nitro, thanks to surely some agreement between AT&T and YP. One example is the contacts list, where AT&T in its infinite wisdom has decided that the most important contact of all is the yellow pages, being the only permanent contact stuck in your list, shrinking your visible actual contacts list:



I don't like it, and I want it gone. I've already uninstalled yellow pages, and the dead button is still there! I will edit an XML to remove it =)

1.) Copy the apk you want to modify from your phone (using root explorer) and transfer to your computer

In this case, I wanted my Contacts.apk, which is in /system/app. Keep a copy safe somewhere, just in case something goes wrong, or you want to revert back to the original apk. The vast majority of system apps are in the /system/app folder, with the major exception of framework-res.apk. This is the phone’s BIG cajone in /system/framework, and as such, should be handled with utmost care. Messing with framework-res.apk incorrectly is an EASY way to brick your phone in a heartbeat.

2.) Decompile your apk

Put the apk in C:\ (I think you can put it in other places, but just for consistency, I'll say put it there =) ). Decompile it by using apktool. You can find more details elsewhere, but to keep it as brief as possible, here's how in a nutshell (there are other ways to do this, where to put files, etc, but for consistency's sake, this is how I do it):

-run cmd.exe
-in the command window, change your directory until you get all the way to C:\ (keep typing "cd.." and hitting enter until you're there)
-in the window type the following and hit enter:

apktool d nameofapk.apk
(In this case, type "apktool d Contacts.apk")

******IF YOU GET A LONG STRING OF "Could not decode attr value..." ENDING WITH "Can't find framework for package of id: 2. You must install proper framework files, see project website for more info." (like you do when decompiling some apk's like SystemUI.apk) SKIP TO THE END FOR SPECIAL INSTRUCTIONS******

-the decompiled apk will now be extracted into a folder of the same name without the .apk extension (here, C:\Contacts)

3.) Find and edit the XML you want!

Now that it's been decompiled, the XML will be magically readable with Notepad++ (before decompiling, opening XML's with a hex editor produces gibberish. Now, you can actually read the text of it!). In this case, the XML we want to edit is here:

C:\Contacts\res\layout-finger\contacts_list_item_top_search_att.xml

In this XML, lines 14, 15 and 16 refer to that stupid bar in Contacts.apk with the yellow pages and ICE buttons. Included in lines 14, 15 and 16 are: android:layout_height="60.0dip", android:layout_height="51.0dip", and android:layout_height="51.0dip", respectively.

Change all 3 numerical values to 0.0 in all three cases, so now in lines 14, 15 and 16, it shows: android:layout_height="0.0dip", android:layout_height="0.0dip", and android:layout_height="0.0dip", instead.

Save the changes to this file and close! (You should have your original apk backed up somewhere else already!)

4.) Recompile the apk with the newly edited XML in it!

In cmd.exe (still in directory C:\), type:

apktool b nameofapkfolder

*do NOT type nameofapk.apk. Leave off the .apk extension! You're recompiling the decompiled folder, NOT the .apk! For example, here to rebuild Contacts, type

apktool b Contacts

This can take a while. It's okay if you get some "has no default translation" lines popping up. Just ignore them.

Now, in that same decompiled folder, you will have a new "build" folder. Inside are your newly recompiled files for your apk!

5.) Find the recompiled XML from the build folder and move it into a copy of the original .apk!

It will be in the same organization as it was within the .apk. For example, that XML we edited is located here:

C:\Contacts\build\apk\res\layout-finger\contacts_list_item_top_search_att.xml

If you open this recompiled XML, you'll see that it's back to being gibberish. That's because it's been successfully recompiled!

Now, find your original, unedited .apk, right click, 7zip, and open archive. Navigate to the original XML in that apk and drag and drop your newly edited/recompiled XML into that folder, letting it overwrite the original one! This is your newly edited .apk with the changes you want in your XML!

6.) Put this newly modified apk back onto your phone. Using root explorer, copy the new apk into the /system folder of your phone.

7.) CHANGE THE PERMISSIONS of the apk to match those of the original apk in /system/app.

In this case, long press on the Contacts.apk, select permissions, and select the check boxes as follows- Owner: Read, Write; Group: Read; Others: Read. This matches the permissions of Contacts.apk in /system/app

8.) Move the new apk into /system/app, and let it overwrite the original!

9.) Restart your phone!

Voila! The stupid bar is gone, and I have a little more room for my REAL contacts!






******SPECIAL INSTRUCTIONS FOR DECOMPILING ERROR******
Some apk's (like SystemUI.apk) require OTHER (framework) apk's be "installed" in order to decompile properly. To install an apk, put it in C:\, then type the following command in cmd.exe when in directory C:\:

apktool if nameofapk.apk

But which other apk needs to be installed?? The secret is that when you try to decompile your apk and it produces those errors, apktool will actually tell you (in its way) what other apk is needed! For example, decompiling SystemUI.apk results in notifications ending in this:

"Can't find framework for package of id: 2. You must install proper framework files..."

id: 2 is your key. In /system/framework, there are 3 other apk's besides framework-res.apk. These are:

RES_cappuccino.apk
RES_model.apk
RES_sui.apk

If you install framework-res.apk:

apktool if framework-res.apk

you get the following statement:

I: Framework installed to: C:\Users\User\apktool\framework\1.apk

This means that id: 1 = framework-res.apk! If you install the other 3 apk's (RES_cappuccino, model, and sui), you'll find that they are:

RES_cappuccino.apk = id: 2
RES_model.apk = id: 4
RES_sui.apk = id: 3

SO, when you try to decompile SystemUI.apk, and it says "Can't find framework for package of id: 2," it's asking that you first install RES_cappuccino.apk before decompiling SystemUI.apk! So before apktool d SystemUI.apk, type:

apktool if RES_cappuccino.apk

It will say, "Framework installed to C:\Users\User\apktool\framework\2.apk

And now, when you decompile SystemUI.apk, it will work (as will recompiling! =) )

Good luck! Godspeed! =)
The Following 19 Users Say Thank You to itiskonrad For This Useful Post: [ Click to Expand ]
 
V@no
Old
#2  
V@no's Avatar
Senior Member
Thanks Meter 110
Posts: 1,118
Join Date: Sep 2007
This is awesome! Thank you very much.
I've successfully managed use Apk Manager 4.9 - Makes Modifying Ur Apk A Breeze (Windows/Linux) for SystemUI.apk, but it did create additional useless folders.

One question though, what about resources.arsc file?
According to apk manager that file needs to be recreated when .xml files are changed.
 
itiskonrad
Old
#3  
Senior Member - OP
Thanks Meter 175
Posts: 238
Join Date: Dec 2009
It seems like that's the case when you have significant changes to the xml, like deleting lines or adding code, etc. When I just change values in the xml, it doesn't seem to require rewriting resources (which I'm not super comfortable with), so until we get a recovery mode, I just try to be creative in how I edit xml's to get what I want by just changing values =)
 
aquariuz23
Old
#4  
aquariuz23's Avatar
Senior Member
Thanks Meter 79
Posts: 829
Join Date: Mar 2011
Location: Clifton, NJ
NICE!! Great job sir!


Motorola Atrix 4G > Unlocked BL!! > GingerBlur 2.3.4 > Navalynt's Mod (v1.4) > Tenfar's CWM Recovery Mod > CM7

LG NITRO HD P930 >> Root via SuperOneClick v2.3.2 >> Bytecode64's CWM v.5.** >> KernelPan!c's v0.3
 
itiskonrad
Old
#5  
Senior Member - OP
Thanks Meter 175
Posts: 238
Join Date: Dec 2009
Did you ever get rid of the headphones icon, by the way? It shouldn't be too tricky
 
V@no
Old
(Last edited by V@no; 27th December 2011 at 05:43 AM.)
#6  
V@no's Avatar
Senior Member
Thanks Meter 110
Posts: 1,118
Join Date: Sep 2007
Quote:
Originally Posted by itiskonrad View Post
Did you ever get rid of the headphones icon, by the way? It shouldn't be too tricky
Well, kind of...I do now know how to remove it, unfortunately it will have to wait until apktool get updated to v1.4.4, because current version does not work for our resources-res.apk (we seem to have ICS formatted .apk's). I already twice soft bricked my phone trying recompile this apk
Once we get the proper tool, we might start getting some interesting mods, like more quick settings for instance.
 
theoski
Old
#7  
Member
Thanks Meter 8
Posts: 70
Join Date: Aug 2007
itiskonrad, can you post the actual file for removing yp from contacts. I am on mac with no pc available at the moment.
 
itiskonrad
Old
(Last edited by itiskonrad; 19th January 2012 at 11:35 PM.)
#8  
Senior Member - OP
Thanks Meter 175
Posts: 238
Join Date: Dec 2009
Sure thing! Here:

Contacts - No Yellow Pages

Be sure to follow steps 6-9, though! Especially the part about changing permissions!
Attached Files
File Type: zip Contacts- No YP.zip - [Click for QR Code] (1.68 MB, 46 views)
The Following User Says Thank You to itiskonrad For This Useful Post: [ Click to Expand ]
 
theoski
Old
#9  
Member
Thanks Meter 8
Posts: 70
Join Date: Aug 2007
Great thanks. Worked great.

Sent from my LG-P930 using Tapatalk
 
PMad
Old
#10  
PMad's Avatar
Senior Member
Thanks Meter 39
Posts: 138
Join Date: Sep 2010
Location: Salem, OR
I couldnt get the new APK Manager which is now called APK Tools to work properly. Since the original link didnt work i decided to search out the old APK Manager to give it a shot, and it worked beautifully! For those that want the old one, you can get it here:

http://www.gamefront.com/files/17870566

i used it to change my contact list to black with white text. Much nicer!

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...