[XDA-University] SXUsr:
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

...in 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.

A BACKUP OF YOUR 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. :silly:

Use Linux or a Mac? See the following threads for more information on using apktool on other Operating Systems...

[WIN/LINUX][Decompile/Compile] Quick Mod Tool 4.0 [decompile and compile with speed]

APK Manager for Mac OS X

[Linux][UTILITY][TOOL] APK Multi-Tool

[tutorial] decompiling,recompiling and signing in linux (27-01-2013)

How to install and use Apktool with Ubuntu

​

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 APKTool_CMD.zip 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...

[B]adb pull /system/ Z1C_368[/B]

...you 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...

[B]adb pull /system/app/ Z1C_368 app
adb pull /system/priv-app/ Z1C_368 priv-app
adb pull /system/framework/ Z1C_368 framework[/B]

...or pull individual files...

[B]adb pull /system/framework/framework-res.apk[/B]

...so 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...

[B][U]apktool[/U] [U]d[/U][/B] 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

...you 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...

[B][U]apktool[/U] [U]b[/U][/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...

[B]java -jar signapk.jar testkey.x509.pem testkey.pk8[/B] 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.

[TOOL] pySignare - Quickly Sign APKs [Windows]

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 [MENTION=3906534]AndroidGraphix[/MENTION] 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...

- Noobs guide to signing an APK with a Private Key​

​

- SOURCE

Move your new signed apk into your APKTool_CMD folder, you can overwrite your original if you want, and use the following command...

[B][U]zipalign -v 4[/U][/B] 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...

[B][U]adb push[/U][/B] 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[B][U] /system/priv-app/[/U][/B]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.

XML 101 - XML Modding Made Easy!

How To Edit Resources

The Ultimate Android Themeing Guide

[GUIDE] Smali coding guide for beginners

[Reference] Interactive Phone Modification [GUIDE]

[TOOL] Android Drawable Resizer Tool

[GUIDE] Want to learn how to theme?

[Guide] demystifying build.prop [Valid entries]

General Questions about Themes GO HERE!!!!!

[INFO] Custom framework-res.apk resources.arsc using vendor overlays

[Tutorial][NICS Themer] Create Your Own Themed apk & Become a Themer

​

U.I Modding

Tutorial :- Changing App Icons

[TUTORIAL]How to Theme Your MMS

[How-to] Edit the "About Phone" display

[Tutorial][VIDEO] Add/integrate apps into Settings app!

[TUTORIAL] Where to find the colors for making a theme

[MOD][GUIDE]LockScreen Clock with seconds[ANY ROM]

[TUTORIAL] How to add various framework/Settings mods

[TUT][JB] HOW TO THEME SystemUI.apk for TOTALLY newbie!

[HOWTO] Integrating/Adding applications to the settings menu

[TUTORIAL][ICS][GB][JB]How to change Android's black background

[GUIDE][Ultimate]Theme Apps To Dark Theme | Theme Whole System | Newbies Here! 12/11

​

Text...

Text Color Guide

[GUIDE] Tips for themers

[GUIDE][REF]Changing System Text Settings

​

Statusbar...

[MOD][TUT] Merge The WiFi And Signal Icons

[GUIDE][MOD][SYSTEMUI] How to add 0.00KB/s meter on statusbar GB/ICS/JB

[TUT] How To Center The Clock On The Statusbar..And Move Other Icons As Well!

[How-To]Removing Battery Percentage, Adding Toggles,Battery Circles to Statusbar

[GUIDE][Mods][All Devices]How to add/ Change Clocks to Analog/ Digital with Seconds

​

​

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

[MENTION=2295247]Diamondbacks[/MENTION] - Virtuous Ten Studio

[MENTION=4315551]Ticklefishs[/MENTION] - [TOOL] Tickle My Android

[MENTION=5078388]BDFreaks[/MENTION] - [Tool]Advanced ApkTool

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

TIP:

Restoring modified files if you mess up is easier and quicker with a CWM.zip, 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.

​

...in 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...

How to edit .9.pngs

[TUTO] Create your 9.png !

[UTILITY][TOOL] 9patchPngSuite [Windows&Linux]

How to draw NinePatch images with Photoshop - .9.PNG

[TOOL][Multi-Platform][.9.png][ALL DPIs] Android Resizer Tool

[Tutorial][Commentary] How To Batch Edit .9PNG/PNG Images

[tool] 9compiler - batch process for themers android

[YOUTUBE]bXJrMO5t0I0[/YOUTUBE]​

​

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 ROM.zip will more than likely wipe your Phone whereas a Theme.zip may just replace files but it might delete some also.[/QUOTE]

See below for a CWM.zip Template but first some helpful links...

[Tool]easy flasher v4 (ur own update.zip)

[Tool][Windows/Linux] Android Flashable Zip Creator

[Utility-Tool][DEVandThemers]CWMflashpack.zipCreatorV1{TheCollective}w/EdifyScripting

ERRORS encountered in CWM Recovery

[TUT] [for NOOB] editing updater-script for noobs!

[TUTORIAL] Making Flashable ZIPs, EDIFY Script, ZIP Signing & Key Creation

​

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...

​

...so 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 [MENTION=3924617]iBotPeaches[/MENTION] and [MENTION=1922851]Brut.all[/MENTION] for making it possible with - Apktool