Remove All Ads from XDA

[Guide/Reference] The Basic APK & Theming Thread... {15/11/15}

7,564 posts
Thanks Meter: 2,616
By XperienceD, XDA Ad-Free Senior Member on 25th May 2013, 02:21 PM
Post Reply Email Thread
Hi there.

The greatest thing about Android is that you can change just about every element of the U.I, and if all you want to do is change a few images it's as simple as copying and pasting, but this guide will teach you how to...

  • Use ADB Commands
  • Deodex
  • Decompile
  • Recompile
  • Sign
  • Zipalign an easy to follow manner that will have you theming your own apks in no time. There are many many GUI programs which I'll link to below that automate the following process but experience has taught me that it's important to know the basic process for when those programs don't work, are no longer maintained or you just don't like them for whatever reason etc, and to be honest command line editing for me is just as quick, and I personally prefer the ability to have everything in one folder. So lets begin.

Some Requirements:
  • A Rooted Phone.
  • Java - Do this first if you don't have it installed already.
  • Notepad++ - An essential program for xml editing!
  • Photoshop or Gimp - You'll need one of these for image editing.
  • 7-Zip or WinRar - Required for apk editing.
  • Patience.
Use Linux or a Mac? See the following threads for more information on using apktool on other Operating Systems...
Quick Tips;
  • .apk files are applications on your Phone, but when they''re on your computer you can browse them exactly like you would a .zip file, so set your default zip program as the default program for handling apks which will makes things much easier when working with them.

  • Download themes for your Phone, for other Phones too even and compare the res folders and screen shots of the theme as that will give you a good idea of what image you need to look for when modding your own apks.

  • If all you want to do is change images then you don't even necessarily need to decompile, you can just drag and drop images in to an apk to replace a stock image so long as they have the same file name.

  • For more complex mods like changing text colors and layouts (.xml files) and editing .9 png images then you will have to decompile.

Most of us will have Java already installed, but if you don't then get it installed before doing anything else. To save you the time and hassle of figuring out what else you need to download etc I've made a zip for you to download which contains Apktool and ADB.

Download to a location of your choice, preferably the C:\ drive which will give you a folder to work from. This is how mine currently looks...

Once your folder is setup, java and other tools installed, you're going to want to get any apks you want to theme off your Phone and there are numerous different ways to this, but we're going to use adb commands to pull files to your computer so we need to open a command prompt window in your Apktool folder. To do this simply hold the shift key then right click your mouse in the Apktool folder and select "open command window here", or just click on the included command prompt.bat.

I like to pull the whole system as soon as I'm rooted as it gives me a backup of stock files which I can then copy and deodex to be themed.

The command to pull your whole system is...
adb pull /system/ Z1C_368 can choose something other than Z1C_368 as your folder name but it will create that folder in your Aktool folder. Alternatively you can just download individual folders, the commands are as follows...
adb pull /system/app/ Z1C_368 app
adb pull /system/priv-app/ Z1C_368 priv-app
adb pull /system/framework/ Z1C_368 framework
...or pull individual files...
adb pull /system/framework/framework-res.apk now you should have a APKTool_CMD folder with another folder within it and at least your app, priv-app and framework folders in that, which we can use for the next step.

The tool I use is this - [Tool/Utility] JoelDroid Lollipop Batch Deodexer. While I will deodex all the files I've pulled to my computer experience and battery life has taught me to only deodex the apps I've themed on the phone, rather than run a fully deodexed ROM.

Before you can do anything else you need to install your framework-res.apk and SemcGenericUxpRes.apk/twframework.apk, which will put two apks at C:\Users\YourPCName\apktool\framework which are the resources apktool uses to work its magic. The two commands to install your two resource apks are...

apktool if framework-res.apk
apktool if SemcGenericUxpRes.apk

The command for decompiling is...
apktool d framework-res.apk

...which will create a folder named like for like except for the .apk extension, and in this folder is where you'll find a couple of folders, the main one always being the res folder as it's in this folder that you'll find your images and xmls to edit. First glance of a decompiled res folder can be overwhelming, 596 folders in my frameworks, but we only need to focus on a handful in the majority of apks, and they are...
  • drawable
  • drawable-xhdpi-v4 (drawable-xxhdpi-v4 depending on your device)
  • layout
  • values may need to delve into others sometimes but it's very rare that I've had to.

Once you've finished making your mods you need to recompile your apk using the following command...
apktool b framework-res

...notice you only use the folder name here. If you get any errors here due to a bad edit apktool will usually tell you, in a roundabout way, you just need to read the code it throws up then retrace your steps, correct any bad edit and try again. If all goes smoothly you'll now have a new folder called dist, which contains your newly modified apk, but you can't use that just yet.

This is where 7-Zip or WinRar comes in to play. We need to extract from the original apk the Android.Manifest.xml and META-INF folder, into the dist folder, then from the new apk extract the resources.arsc also into the dist folder, then drag and drop all three files back into the new apk, but NOTE, it's important that you choose store as the compression method, any other will break the apk, and if you replace a broken framework-res.apk you will bootloop.

And signing is as simple as that. Alternatively you can use the following command...
java -jar signapk.jar testkey.x509.pem testkey.pk8 framework-res.apk.apk framework-resS.apk
...notice the extra "S", the output name has to differ from the input name otherwise it will give an error, if done right it will create a new apk called framework-resS.apk, just remember to rename it back to the original before using it on your Phone.

Signing For The Play Store

If you plan on Publishing a Theme or any other app/apk to the Play Store then using the above method to sign your apks just wont work because you need to give it an individual signature that is unique to you, thankfully @AndroidGraphix has written a great guide that will show you how, it's a bit more fidgety than the above method but simple enough to follow...
Originally Posted by AndroidGraphix

- Noobs guide to signing an APK with a Private Key



Quite understandably, situation would be reserved for unaligned application packages. Resource reading would be slow and memory usage would be on the higher end of the spectrum. It would also depend on how many unaligned applications are present. For example, if less number of applications with an unaligned home application, you’d see slower application launch times. This is the best case scenario. For a worst case scenario, having a number of unaligned applications will result in the system repeatedly starting and killing processes, struggling with lags and huge battery drain.


Move your new signed apk into your APKTool_CMD folder, you can overwrite your original if you want, and use the following command...
zipalign -v 4 framework-res.apk ZAframework-res.apk

...notice the ZA, zipaligning creates a new apk which has to be named different from the original, but use what you want, it'll need renaming again before you use it.

So now we need to transfer your apk back to your Phone, you can do it by copying to your SD, then to your system, change permissions, then copy to the right folder, but that's not only time consuming but highly tedious too, so a simpler method is to use adb using the push command as this allows us to push straight to the system overwriting the original with the correct permissions too. To use this method you'll need you'll need an unsecure kernel and/or Chainfires adbd Insecure app. Try the app first but if you still can't mount and push files read this thread - [HOW TO]Make your favorite kernel adbd insecure to run ADB as root on /system and try again.

Rename your zipaligned apk to it's original name, then we need to mount the system before we can push direct to the the system, and the command for that is...
adb remount
...then we need to make sure we're pushing our apk to the right folder on the Phone, so for the framework-res it's...
adb push D:\Xperia\Z1C_368\APKTOOL\framework-res.apk /system/framework
...yet for the SystemUI it's...
adb push D:\Xperia\Z1C_368\APKTOOL\SystemUI.apk /system/priv-app/SystemUI
...if it's any one of those two then generally you need to reboot, so just type...
adb reboot
...your Phone will restart and if you've done everything right your new mods should be displayed, happy days. So that's it for how to use command prompt for modifying apks.

So now you know how to prepare an apk for editing your going to want to theme it obviously, and the following links will help you with that.
U.I Modding

The three best/most popular GUI programs are...

...there are others but these are I what I tend to see referred to the most.


Restoring modified files if you mess up is easier and quicker with a, especially if you're modifying any framework apks! Just because an apk might build with no errors doesn't mean it won't give you any when installed to the Phone.

I hope after reading this explanation you're left wondering what all the fuss is about, as it really is quite simple. I'll use the following two images, btn_default_pressed_holo.9 & status_bar_close_off.9 to illustrate the basic point of the borders...

Decompiled .9pngs:
Recompiled .9pngs:
Those borders control which part of the image is stretched (Left & Top) and where on the image content will be displayed (Right & Bottom). We'll use Draw 9-patch which is for editing the borders of decompiled .9pngs and lets you see how the image, when stretched, will be displayed on the Phone. Notice that the borders are different sizes, well that's because I only want/need a certain part of the image to stretch to get the desired look on the Phone. the image below the left side shows the stretched image and desired effect should look on the Phone and the right side shows how it would look if I had edited the borders incorrectly or used none at all...
You can get away by not using a border but you would need to edit your image to specific dimensions to accommodate for the stretching, for example it might look fine for a simple OK button but it might not look right if you used the same .9png for a screen press which stretches the whole length of the screen, so you're better off just using them to begin with, plus you'll more than likely get errors down the line while decompiling or recompiling your apk.

The use of the border is made even more clear when you add text to an image. For my status_bar_close_off.9 I've filled all four sides of the image (except for an empty pixel in all four corners as that is the max amount of border you can use) as I need it to stretch the image just how I've edited it...
...but if I used the same sized left side border as the btn_default_pressed_holo.9 then this is how it would look on the Phone...
...which is obviously not the look I'm trying to achieve, as the left side border is causing the image to stretch incorrectly.

So that's basically it, depending on the image you're editing you can usually leave the borders alone but if you create one from scratch then you might need to play about with them if your images doesn't look quite right when used on the Phone. Here's a few links that will assist you further, especially the batch editing...

ClockworkMod Recovery zips are used for flashing individual files to whole ROMS and can be a life saver if you push a badly edited apk to your Phone that results in a bootloop. There's also a few programs that can assist you with that too, but if all you're doing is replacing a few files all you really need is a template, then it's just a matter of creating the Phones folder setup in the zip which is simply creating folders: system\app - system\media\audio etc then dragging and dropping your files into it. A basic understanding of the updater script is essential, a will more than likely wipe your Phone whereas a may just replace files but it might delete some also.[/QUOTE]

See below for a Template but first some helpful links...
This is my Restore_zip which is set up so you can add your own files to the framework and apps folders in the main system location, but you can easily add other folders to it if you want to add things like fonts, tones or anything else, just remember to add folders within folders if that's where the files you want to include are such as tones, media\audio\alarms for example.

If you navigate to META-INF\com\google\android you will find the updater-script which controls how the zip works and the text you see when you run it in CWM. As this zip is just for basically over writing files you don't need to edit anything except for a few lines...
...this is how I've edited it for my theme... just edit it using Notepad++ to your liking.

When adding files to your zip add them using Normal as the Compression Method...
...Remember to remove the text files I've added otherwise they will be flashed to your folders too.

And that's pretty much it, the only way you're really going to learn is by reading then putting into practice what you've read and picking stuff up along the way, fortunately there are numerous guides for numerous mods and tools to help with a variety of tasks.

Notable credits and thanks to @iBotPeaches and @Brut.all for making it possible with - Apktool
Attached Files
File Type: zip - [Click for QR Code] (130.0 KB, 32 views)
The Following 77 Users Say Thank You to XperienceD For This Useful Post: [ View ] Gift XperienceD Ad-Free
25th May 2013, 02:21 PM |#2  

Originally Posted by rovo89

In this thread, I'm presenting a framework which gives you the possibility to modify your ROM - without modifying any APK (developers) or flashing (users)!

  • No need to modify any APKs. This means:
  • No need to decompile, change things in smali, compile, sign, ...
  • It will work for odexed and deodexed ROMs.
  • Your mod is not bound to a specific version of the ROM. Unless there is a major change in the methods called for a certain functionality, your mod will continue to work even when you upgrade your ROM. Hell, it will probably even work with different ROMs.
  • Multiple mods can be installed at the same time, even if they change the same package. So you can use these battery icons and those quick toggles. Even hooking the same method twice is possible. Of course, this only works properly if the mods are not trying to do incompatible things.
  • It does its magic at runtime. That means you can implement options to let the user decide if they prefer the bikeshed to be painted in red or blue. Or you can have some extra logic for certain ROMs without building different mod versions.
  • It can be disabled easily without having to reflash.
  • It's open source.

- [FRAMEWORK ONLY!] Xposed - ROM modding without modifying APKs

Originally Posted by Annex1


Theme book was created by Annex and Ebs512. I've been asked alot of questions from how to get started? what do I need to get started? to What Graphics program do I use? etc. We made a real simple theme guide to help get you started. This is in Layman Terms.. Nothing fancy.


- [GUIDE] HOW TO THEME CM10.1 - Animated Book
The Following 23 Users Say Thank You to XperienceD For This Useful Post: [ View ] Gift XperienceD Ad-Free
25th May 2013, 02:22 PM |#3  
Random Stuff...

Originally Posted by ttibbetts83

here are some links for ubuntu installs that will help with .apk modding on ubuntu for those who want it

how to setup apktool on ubuntu

ubuntu version of

xaraxtreme looks to be a good program from what i have read but i have not tryed it out yet

gimp is avalable through ubuntu software center and for .xml ubuntu has built in editer software just by right click and open with text editer

Originally Posted by XperienceD

Originally Posted by cickii

can someone please tell me which xml is responsible for the blue / gray colors in the picture below.

Finally sussed it. It's LinearColorBar.smali found at Settings\smali\com\android\settings\applications, search for 0x99cc and -0xff6634 and change them for your own colours...

Originally Posted by XperienceD

Hi all.

Just a short write up as a follow on from THIS thread as this is relatively quite simple.

So you want to change your notification background from the plain dark color to something a bit more your style...

...well all you need to do is decompile your SystemUI.apk and navigate to the values folder and open up your drawables.xml and you should see something like this...

    <item type="drawable" name="notification_number_text_color">#ffffffff</item>
    <item type="drawable" name="notification_item_background_color">#ff111111</item>
    <item type="drawable" name="notification_item_background_color_pressed">#ff257390</item>
    <item type="drawable" name="ticker_background_color">#ff1d1d1d</item>
    <item type="drawable" name="status_bar_background">#ff000000</item>
    <item type="drawable" name="status_bar_recents_background_solid">#e5000000</item>
    <item type="drawable" name="status_bar_recents_app_thumbnail_background">#88000000</item>
    <item type="drawable" name="status_bar_notification_row_background_color">#ff090909</item>
    <item type="drawable" name="notification_header_bg">#ff000000</item>
    <item type="drawable" name="notification_tracking_bg">#e5000000</item>
    <item type="drawable" name="recents_callout_line">#99ffffff</item>
    <item type="drawable" name="notification_item_background_legacy_color">#ffaaaaaa</item>
Simply change these two lines...

<item type="drawable" name="notification_item_background_color">#ff111111</item>
<item type="drawable" name="notification_item_background_color_pressed">#ff257390</item>

<item type="drawable" name="notification_item_background_color">@drawable/status_bar_item_background_normal</item>
<item type="drawable" name="notification_item_background_color_pressed">@drawable/status_bar_item_background_pressed</item>
...then add two .9 png images of the same name, status_bar_item_background_normal and status_bar_item_background_pressed to your drawable-hdpi folder, recompile, zipalign, push to your Phone, done.

Quick Tip: If you can't create a .9 from scratch just edit the first two in drawable_hdpi which in my folder is alert_bar_background_normal.9 and alert_bar_background_pressed.9, just remember not edit over the .9 borders.

The Following 12 Users Say Thank You to XperienceD For This Useful Post: [ View ] Gift XperienceD Ad-Free
25th May 2013, 04:31 PM |#4  
jacknb1ack's Avatar
Flag Yogyakarta
Thanks Meter: 71
hello XperienceD,

first i want to say thank you, finally i can make some modifiaction of my rom, i am managed to get 3-wa-power on my stock rom, show full option in developer setting, change color and icon, etc (still far from my target though).

for now im trying to make my phone running holo dark themes (default is light), at first it looks fine, background change from light to dark, text black to white.

but now i found some color problem, can you help me locate color setting for this :

Click image for larger version

Name:	Screenshot_2013-05-25-21-35-00.jpg
Views:	1092
Size:	12.0 KB
ID:	1990170

Click image for larger version

Name:	Screenshot_2013-05-25-21-40-07.jpg
Views:	1162
Size:	25.2 KB
ID:	1990171

Click image for larger version

Name:	Screenshot_2013-05-25-21-40-21.jpg
Views:	1081
Size:	21.6 KB
ID:	1990172

Click image for larger version

Name:	Screenshot_2013-05-25-21-41-40.jpg
Views:	1047
Size:	23.3 KB
ID:	1990173

and for setting color, i want to change text color to holo_blue

for now, i am doing bruteforce, line per line, hope can fix this tonight, but if anyone know the where should i change the color setting, i am more than happy to accept it

The Following User Says Thank You to jacknb1ack For This Useful Post: [ View ] Gift jacknb1ack Ad-Free
26th May 2013, 08:46 AM |#5  
Originally Posted by jacknb1ack

but now i found some color problem, can you help me locate color setting for this :

Check the links above "where to find colors" and "changing system text".
26th May 2013, 03:01 PM |#6  
jacknb1ack's Avatar
Flag Yogyakarta
Thanks Meter: 71
great, i think i've clicked all the link in ur post ... but looks like i've missde some link xD ...

thanks again.
18th June 2013, 11:08 PM |#7  
Originally Posted by jacknb1ack

great, i think i've clicked all the link in ur post ... but looks like i've missde some link xD

Did you find it in the end?
19th June 2013, 05:50 AM |#8  
Junior Member
Flag North Sulawesi
Thanks Meter: 1
Thumbs up
nice tutorial
20th June 2013, 11:27 AM |#9  
jacknb1ack's Avatar
Flag Yogyakarta
Thanks Meter: 71
Originally Posted by XperienceD

Did you find it in the end?

yes .. thanks to you and all developers and themer here, i can finish my own customizing rom xD

and lately i've found that its need to resign all system apps to do better in what i want, and here is my last work xD
20th June 2013, 05:17 PM |#10  
Originally Posted by jacknb1ack

yes .. thanks to you and all developers and themer here, i can finish my own customizing rom xD

Nice 1.

Originally Posted by jacknb1ack

Post Reply Subscribe to Thread

apktool, decompile, guide, how to, theme

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes