[XDA-University] Ticklefish:
*** Do NOT Edit "public.xml"!! ***​

I've seen a lot of tutorials on xda and other forums which say, at some point, something like this:

I never do this, I always leave public.xml alone, and it's probably time I explained why.

First, let's take a look at what public.xml actually is and what it does.

You'll find this file in the "res\values\" folder of your decompiled apk and it looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<public type="attr" name="type" id="0x7f010012" />
.....
<public type="drawable" name="somc_sys_wifi_signal_null" id="0x7f0201b4" />
.....
<public type="mipmap" name="ic_launcher_dreams" id="0x7f030001" />
.....
<public type="layout" name="navigation_bar_sw600dp" id="0x7f040009" />
.....
<public type="anim" name="wallpaper_recents_launch_from_launcher_exit" id="0x7f05001a" />
.....
<public type="xml" name="somc_skin_permissions" id="0x7f060000" />
.....
<public type="array" name="config_fullBatteryVibrationPattern" id="0x7f07000f" />
.....
<public type="id" name="traffic" id="0x7f0800ac" />
.....
<public type="color" name="somc_quick_settings_tabwidget_text_colors" id="0x7f090016" />
.....
<public type="bool" name="config_miniTablet" id="0x7f0a0013" />
.....
<public type="string" name="done_button" id="0x7f0b00fe" />
.....
<public type="integer" name="status_bar_config_maxNotificationIcons" id="0x7f0c0013" />
.....
<public type="dimen" name="status_bar_recents_thumbnail_top_margin" id="0x7f0d004f" />
.....
<public type="style" name="TextAppearance.StatusBar.PhoneTicker" id="0x7f0e001d" />
.....
<public type="plurals" name="status_bar_accessibility_recent_apps" id="0x7f0f0000" />
.....
<public type="menu" name="tools_popup_menu" id="0x7f100002" />
.....
</resources>

This is the public.xml from my phone's SystemUI.apk. I've had to take some of the lines out, the whole file is over 1,300 lines long!

In fact, public.xml is probably the longest XML file you'll have in your APK files. This is because it lists all the individual parts of the APK. All the images, id's, strings, colours, styles, etc.

Each of those parts is allocated an unique hexadecimal reference. These references are known as "Resource ID's". There's a very handy post on stackoverflow that details just how Resource ID's are allocated:

(You can find the original post here: http://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work/6646113#6646113)

Resource ID's are used in the Java side of the app. Although every part of an APK gets a resource ID allocated to it, not every resource ID is used in the Java.

Here's the line of XML that displays my status bar clock:

<com.android.systemui.statusbar.policy.Clock
android:textAppearance= [MENTION=220439]st[/MENTION]yle/TextAppearance.StatusBar.Clock"
android:gravity="start|center"
[color="red"]android:id="@id/clock"[/color]
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:singleLine="true"
android:paddingStart="6.0dip" />

This is the line in my public.xml that assigns a resource ID to "@id/clock":

<public type="id" name="clock" id="[color="red"]0x7f08002d[/color]" />

And this is a little snippet of smali code that uses that resource ID:

iget-object v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, [color="red"]0x7f08002d[/color]

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

invoke-virtual {v1}, Landroid/view/View;->getWidth()I

move-result v1

add-int/2addr v0, v1

So what's the problem with adding lines to public.xml? Well, there's actually three problems..

It's very time-consuming. For everything that you're adding to public.xml, you have to work out what the next available hexadecimal reference is. The resource ID's aren't always in numerical order so you might have to search for the number you want to use to make sure it's not already taken.

And, if you've got more than one or two lines to add, it's a lot of typing.

It's easy to get wrong. Even if you're adding resource ID's that aren't already taken, you still might get a compiling error saying that the number's too high, or something similar. Which means you have to go back into public.xml, work out another hexadecimal number and try that one. Which takes even more time.

And the main problem....apktool will automatically do it for you anyway! Apktool uses a piece of software called "aapt".

Sound familiar? It should. Remember that quote from earlier?

That's right. If you add lines to public.xml, all you're doing is something that would happen when you recompile anyway.

Of course, if you want to waste time and effort doing something completely unnecessary, that's your decision...:p

*** Don't DELETE "public.xml" Either!! ***​

I've seen more than a few posts suggest deleting public.xml, normally if people are having difficulty getting the new resource ID's right.

Hopefully by now, you can see why this isn't necessary but it can also cause your app to crash!

The trouble is that you can't guarantee that the new resource ID's will be the same as the old ones..

Admittedly, this quote is talking about compiling brand new APK files but the point remains. Remember this line of code from earlier?

<public type="id" name="clock" id="[color="red"]0x7f08002d[/color]" />

If I delete public.xml and recompile my APK, the file will be remade but it's possible that this line will change..

<public type="id" name="clock" id="[color="blue"]0x7f08002e[/color]" />

..but the line in the smali won't.

const v2, [color="red"]0x7f08002d[/color]

So the new app will run, try to display the clock, can't find it and Android will force the app to close.

Whoops.

So, to summarise, if you spot a tutorial or a mod that tells you to edit public.xml.....don't. You never need to.