TUTORIAL - decompiling/editing XML

Search This thread

itiskonrad

Senior Member
Dec 5, 2009
361
307
Google Pixel 6 Pro
**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:

2011-12-25110928.png


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!

2011-12-25103508.png





******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! =)
 
Last edited:

itiskonrad

Senior Member
Dec 5, 2009
361
307
Google Pixel 6 Pro
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 =)
 

V@no

Senior Member
Sep 24, 2007
1,473
197
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 :eek:
Once we get the proper tool, we might start getting some interesting mods, like more quick settings for instance.
 
Last edited:

theoski

Senior Member
Aug 29, 2007
70
8
itiskonrad, can you post the actual file for removing yp from contacts. I am on mac with no pc available at the moment.
 

steveboss

Senior Member
Apr 4, 2012
855
1,591
Bratislava
www.uniquewatchfaces.com
***Editing XML's***

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

Hi, I have a problem, I can not correctly open the XML files from ROM. I want to edit the file primary_text_dark.xml of framework-res \ res \ I can not see it correctly. Help me please, the XML files from ROM, I can not correctly open and edit in any xml editor. What is the trick? :confused:
example
https://lh5.googleusercontent.com/-Mlx3d1--g0E/T7yNMCOcCyI/AAAAAAAAAcE/aIV-2zHN8x8/s720/fotka%2520%252014.jpg
 
Last edited:
  • Like
Reactions: cyrusalmighty

itiskonrad

Senior Member
Dec 5, 2009
361
307
Google Pixel 6 Pro
What you are looking at is a non-decompiled xml that is unreadable. You need to first decompile the apk which carries the xml you want to edit in order for it to be readable. You first have to complete steps 1 and 2 and decompile framework-res.apk as described in the guide in order to get a readable primary_text_dark.xml.
 

JSS³

Member
Jul 31, 2011
45
20
Porto Alegre - RS
Error...

Hello everyone!
Dude, thanks for the post. It is very clear!

I have a question. I did everything step by step to decompile the framework-res and edit it, but when I try to recompile it, the APK folder created inside the new folder BUILD is empty.

What can have happened?

(translation via Google Translate)
 

itiskonrad

Senior Member
Dec 5, 2009
361
307
Google Pixel 6 Pro
Hmm, not sure. Try decompiling and recompiling immediately after without making any changes, just to make sure the commands are working. If that doesn't work, maybe there's something wrong with the commands? For example, I know it sounds stupid, but make sure to recompile, you're typing
apktool b framework-res
NOT
apktool b framework-res.apk
 
  • Like
Reactions: JSS³

JSS³

Member
Jul 31, 2011
45
20
Porto Alegre - RS
Thank you Itiskonrad!

Yes, the commands are working. Decompiled and compiled again without changes, and everything went well.
I realized that change depending on what I do when this error occurs. Now I'm changing slowly and has not worked.

The strange thing is that I do not see the changes on the device. My intention is to change the entire text of the notifications in order to use a black theme in my status bar.
I made a theme based on UotKitchen and I'm improving, but notifications such as downloads and ongoing calls persist with the font color black, which makes their visibility.

I will continue testing until something works!
Big hug!

(translation via Google Translate)
 

FlintPNZ

Senior Member
Mar 15, 2012
59
15
Penza
itiskonrad,
Do you use an ICS leak? Could you please modify status bar apk and remove carrier from there? :)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 20
    **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:

    2011-12-25110928.png


    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!

    2011-12-25103508.png





    ******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! =)
    2
    What you are looking at is a non-decompiled xml that is unreadable. You need to first decompile the apk which carries the xml you want to edit in order for it to be readable. You first have to complete steps 1 and 2 and decompile framework-res.apk as described in the guide in order to get a readable primary_text_dark.xml.
    1
    Sure thing! Here:

    Contacts - No Yellow Pages

    Be sure to follow steps 6-9, though! Especially the part about changing permissions!
    1
    ***Editing XML's***

    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

    Hi, I have a problem, I can not correctly open the XML files from ROM. I want to edit the file primary_text_dark.xml of framework-res \ res \ I can not see it correctly. Help me please, the XML files from ROM, I can not correctly open and edit in any xml editor. What is the trick? :confused:
    example
    https://lh5.googleusercontent.com/-Mlx3d1--g0E/T7yNMCOcCyI/AAAAAAAAAcE/aIV-2zHN8x8/s720/fotka%2520%252014.jpg
    1
    Hmm, not sure. Try decompiling and recompiling immediately after without making any changes, just to make sure the commands are working. If that doesn't work, maybe there's something wrong with the commands? For example, I know it sounds stupid, but make sure to recompile, you're typing
    apktool b framework-res
    NOT
    apktool b framework-res.apk