[HTC One S] he_stheone64:
This guide assumes you already know how to use apktool and / or apkmanager. If you don`t, there are plenty of guides already on XDA.

Latest Sense 4.0 and apktool are not great friends. The 3 most important files framework-res.apk, com.htc.resources.apk and systemui.apk all create fatal errors, when using latest apktool 1.43 version. Apktool`s error log is always a big help to solve compile issues, but you need a bit of compile and coding experience to finally solve these. After I stumbled about many people having Sense 4.0 compile issues, I decided to post this guide. Hopefully this will encourage more guys to add mods to One S, after they might have hit a wall before.

Credits:

brut for his awesome apktool

daneshm for original apkmanager

Known issues: ATM com.htc.resources fix does not work with One X

1. Framework-res.apk

a) Since ICS apktool creates multiple plurals errors, but you can easily fix these by using a custom version of apktool. Now updated incl. latest smali baksmali properties for ICS (thx fernando)

Custom ICS apktool version - http://minus.com/mIA3OFkYq/19

b) if you get tag errors like these

anims.xml:3: error: Found tag anim where item is expected

layouts.xml:3: error: Found tag layout where item is expected

raws.xml:3: error: Found tag raw where item is expected

Replace all tags in layouts.xml in values folder with:

<item type="layout" at the front and </item> at the end

Replace all tags in anims.xml in values folder with:

<item type="anim" at the front and </item> at the end

Replace all tags in raw.xml in values folder with:

<item type="raw" at the front and </item> at the end

2. Systemui.apk

When trying to decompile systemui, you will get bad magic value errors. Solution is to decompile without classes, as long as you don`t need to edit smali code. Even if you need to do that, you can still decompile classes.dex separately with smali baksmali.

a) Use -s switch when decompiling to copy classes.dex instead of decompiling it

java -jar apktool.jar d -s systemui.apk systemui-decoded

b) If you are using apkmanager, you can just export classes.dex, then delete classes inside the apk. Then decompile, edit, compile and add classes.dex back when ready.

EDIT: with updated apktool version systemui now compiles fine incl. classes.dex

3. com.htc.resources.apk

Here you get nice layouts tag errors and public entry issues. Again there`s an easy fix for that.

a) Replace all tags in layouts.xml in values folder with:

<item type="layout" at the front and </item> at the end

<resources>
<item type="layout" name="htc_list_item_imageicon_text">@layout/zzzz_htc_list_item_imageicon_text</item>
<item type="layout" name="pin_keyboard">@layout/zzzz_pin_keyboard</item>
<item type="layout" name="zero_dummy_layout">@layout/alert_dialog</item>
<item type="layout" name="htc_list_item_2text_2stamp">@layout/zzzz_htc_list_item_2text_2stamp</item>
<item type="layout" name="htc_list_item_2text_bright">@layout/zzzz_htc_list_item_2text_bright</item>
<item type="layout" name="htc_list_item_image_2text_image_bright">@layout/zzzz_htc_list_item_image_2text_image_bright</item>
<item type="layout" name="htc_list_item_imageicon_2text_2stamp">@layout/zzzz_htc_list_item_imageicon_2text_2stamp</item>
<item type="layout" name="htc_list_item_separator">@layout/zzzz_htc_list_item_separator</item>
<item type="layout" name="htc_list_item_dlna_1">false</item>
</resources>

b) Delete entry "zero_dummy_dimen" in public.xml - it will be created correctly again during compile

In case you still have issues, here is my apkmanager build environment, that works fine with all these fixes.

http://minus.com/mIA3OFkYq/20

Hex editing solution for latest com.htc - thx to tbonanno231 - http://xdaforums.com/showpost.php?p=32222697&postcount=112

Latest apktool version 1.4.9 from ibotpeaches

Big thx to ibotpeaches for the tremendous follow up on apktool

Fixes plural errors

Fixes item tag errors

Fixes bad magic value errors

Adds ICS smali properties (compared to latest official version from brutall)

Fixes unknown folder issues (only with patched aapt.exe)

Download apktool 1.4.9:

http://sdrv.ms/T0LpzK

Download patched aapt.exe

http://sdrv.ms/Mfrkaa

c) Workaround for One X ROM´s

Since many of you guys might only be in need to decompile all the .9`s in com.htc.resources, there is a workaround that allows you to compile these.

Decompile with:

1. java -jar apktool.jar d --keep-broken-res com.htc.resources.apk com.htc.resources-decoded

This ignores all errors and decompiles the apk incl. all patched pngs.

2. Make your changes and copy the changed png`s in any given decompiled apk (I use calendarprovider.apk for this task, very slim apk, compiles fast...) and compile them