[HTC One V] mcgi5sr2:
apks and apktool

OK so hopefully we now know where all the lovely .apk files are hiding within the file structure of our rom. Which don't get me wrong is nice enough in itself, but what we really really wanna do is open these bad boys up and start editing them just the way we like it.

The simplest way to do this is with 7zip or fileroller, you should be able to just double click pop them open, then navigate to the res folder where you will find all the folders with the .png and .9.png s for the gui systems in the app. If your using gimp or photoshop or pretty much any paint related software you can immediately go ahead and edit the .png files. The smart thing to do here is not to replace any files but edit and save them as the same resolution, as you may have noticed that the different res folders are separated into different resolutions and upright and sideways display. For the HOV most of what we want will always be in teh HDdpi or xHDdpi folders. Do Not Edit the .9.pngs As this will result in the failure later. This method is only really useful if your lazy, and only want to grey-scale a single image or what.

If you've got this far you probably want to be able to edit the .9.png s and start opening and changing the .xml code so that you can edit default backgrounds and text colours. To do this we will want the excellent apktool,

http://code.google.com/p/android-apktool/

This tool will unpack the .apk file and allow us to rebuild it as well, however it is rom specific to some degreee, as some .apks have been created using a different aapt file (Slim, some AOKPs) and so will require a more specific version. This may sound like a pain, but it can be dealt with super easily.

The slim one can be found here and has just recently been updated to handle Slim4.4 apks

https://github.com/SlimRoms/apktool

So how do I install, and then run these tools? How do I swap between slim and aosp or other .apktool versions?

First is first, download the version of the tools you want, either through direct link on the googlecode page or from downloading as .zip from the github page. Its worth noting that the latest apktool (v2) which works with java1.7 and can be downloaded from the github works slightly differently from the guide here, but its easy to work out how and is documented on the website.

I am going to assume we are too lazy to read the website, in which case stoppit go back read the website!

That done we can now run the install.sh script in terminal which will create an apktool folder where we can run the tool to our delight.

Importantly it should also put an aapt, apktool, and apktool,jar file into our /usr/local/bin/

Please note that any file structure starting with / is from the true root of the file structure whereas any with ~/ will be starting from your root folder in my case /mcgi5sr2/

This is one place where files go that you can execute anywhere within your file structure, so you can apktool anywhere in your file structure, please not that the decompiled files will always end up in your ~/apktool/<fileName>.apk folder.

So with this knowledge we can rip the aapt, apktool and apktool.jar out of the slimapktool, rename and put them in the /usr/local/bin/ folder for safe keeping. To use them in the heat of battle we simply rename the exisitng ones to 1.5 or 2 or whatever really, then change the name of the slim files back to aapt, apktool and apktool.jar . This way we can swap between them with ease. There are other ways of doing this, but they are beyond my ken (understanding).

OK so we are now installed, and can swap between apktool versions and have an apktool folder! We can really begin.

Delve into you rom or phone and pull out systemUI.apk from your rom/system/app folder and framework-res.apk rom/system/framework/ folder. This can also be done using adb

adb pull /system/systemUI.apk /apktool/systemUI.apk
adb pull /system/framework/framework-res.apk /apktool/framework-res.apk

Should do the trick, With some HTC roms ie stock you may find you need to also pull the htc-framework-res.apk. Once this has been done then one of the most important steps takes place. We extract the file framework for the rom so that we can decompile and recompile successfully for the phone. From within the same folder as the systemUI.apk and framework-res.apk on your computer type:

apktool if systemUI.apk
apktool if framework-res.apk

this will create a framework folder within ~/apktool/ which should contain a 1.apk and normally a 127.apk these are SUPER important let them be.

Finally it seems we are ready to decompile the .apk file we wanted to edit, a good place to start is the phone.pk or mms.apk so move the file wherever, I use the ~/apktool/ folder for all this craziness. Then type:

apktool d mms.apk

The magic should happen and you will have a ~/apktool/mms folder! In which is basically a lot of the same stuff in the unzipped version we talked about earlier. This can be edited to your delight and then recompiled, in fact its worth recompiling immediately to check it all works, nothing more annoying than spending a long time working in your res and values folders only to have it not recompile! So,

apktool b mms

Note the fact that the .apk is no longer present this is because we are building using the folder as source.

We are not done! We need to make sure the certification and signing is all correct, so we need to open the original .apk file, and extract the AndroidManifest.xml and the META-INF folder and replace the ones in the ~/apktool/mms/build/apk/ folder this will make sure we have the original signatures. Then we

apktool b mms

one final time, now the finished mms.apk should be in ~/apktool/mms/dist/ folder ready for use in the rom.

Once decompiled not only can we edit the .png files in the res/drawable folders but we can edit the .9.png files and the .xml and if we are really know what we are about the .smali files. I strongly recommend staying away from smali unless you really know whats up. There is an important rule to follow when editing .9.png files as well, that you should not alter the black lines that surround the edges. Everything else can be edited bar them.

As you can see above these lines normally only a pixel or so wide, but play an important role in how the files are used, stretched, repeated etc. In fact in some cases I have found that even using black (rgb ff000000) caused problems so I used just off black (rgb ff010000). The RGB codes used in the .xml files are also slightly different to normal, the first two digits represent how transparent the colour is with ff being solid, and 00 being transparent.

.xml files of interested will undoubtedly be found in the /res/values folder, as this is where most of the colours are defined.

There are a lot of things that can go awry in this, but if you follow these instructions you should be cool. Any issues you can try me, or go for the mega thread on apktool listed at the top.

A few pointers on what you'll find in the different folders once you've decompiled the .apk can be found in the post below about SystemUI.apk and Framework-res.apk