Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,728,708 Members 54,179 Now Online
XDA Developers Android and Mobile Development Forum

[Advice/Reference/Guide] The Definitive APK Modding & Theming Thread... {09/03/14}

Tip us?
 
XperienceD
Old
(Last edited by XperienceD; 27th April 2014 at 02:13 PM.)
#1  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Tutorial [Advice/Reference/Guide] The Definitive APK Modding & Theming Thread... {09/03/14}

Hi there.

I started this thread to try and simplify the process of modding and themeing Android, there are guides a plenty out there but I wanted to provide something a bit more complete and that covers a bit more than just the decompiling and building an apk to make a specific mod. For example, many guides leave out the zipalign process which you'll read below is quite important, so I've tried to write this as something I would have liked to have read when I first started to learn how to theme which in the long run might just save you a lot of time.

Minimum Requirements:Theming Requirements:
  • Notepad++
  • Photoshop, GIMP or any other image editing software.
  • Patience.
If you get any java not found issues you need to set up the PATH for it in your Environment Variables, you can find a short Guide on how to HERE.

This is how mine looks...


...but it should be there after you install Java.
Code:
C:\Program Files (x86)\Java\jre6\bin;
Quick Tips;
  • 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 .9 png images then you will have to decompile.

  • You may or may not need Android SDK but if you don't want to you can download this Apktool_2.9.03.zip that you can extract to a folder and place anywhere you want on your Computer (I recommend C:\Apktool_2.9.03), then you can run any adb, apktool, zipalign, Baksmali or signing command prompts from it. I've included a Text file with a list of the most common commands you'll need so you can just copy and paste them into the cmd window.


We'll start how I started which I recommend learning first because whilst using a program is great sometimes you can run into issues if your firmware or the program is updated which may cause a conflict, so if and/or when then does happen you'll know how to do things manually.

Getting APKs To Your PC

You have two options here...

1. Use a file manager on your Phone to copy and paste files to your SD, then connect to your PC and use Windows Explorer to copy and paste to your desired location.

2. ADB. Open a command prompt window in the ADB folder (see below) and type/copy the following command...
Code:
adb pull /system/app/ Original_apps
...which will pull the whole app folder to your computer and create a new folder called Original_apps, which you can then simply copy apps to the main folder ready to be modified (keep the Original_apps folder as a backup). Then do the same for your framework folder...
Code:
adb pull /system/framework/ Original_framework
...want to pull your Phones whole system...
Code:
adb pull /system/ Name_of_your_Phone
Further Information:
Installing Resources

For apktool to work you need to install the resources needed by your apks for de and recompiling, and those resources are other apks, the first apk regardless of your Phones manufacturer is going to be your framework-res.apk. The second apk you need is dependent on the manufacturer so you need to check your framework folder for another apk such as twframework.apk or SemcGenericUXpres.apk. Put those two apks in the Apktool_2.9.03 folder to begin with then open a command prompt window. The easiest way for me is holding the shift key then right clicking the mouse and selecting Open command window here, but if you're not able to do that then click your Start button and search for Command Prompt, then open it. You then need to point it to the relevant folder, so type cd then copy and paste the location of the folder (cd C:\Apktool_2.9.03) and hit enter.

The install commands are...
Code:
apktool if framework-res.apk
...and for the second resource apk...

Code:
apktool if SemcGenericUXpres.apk

Decompiling

Then once you've done that, the command to decompile is...
Code:
apktool d framework-res.apk
...and so on for each individual apk you want to modify. A new folder will be created that is named after the apk you are modding, then you can edit xmls, smali files and .9png images. You'll notice that there are a lot more folders when you decompile an apk, that's normal as those folders are from the resources.arsc and where you'll find the xml files you may need to edit to make the changes you want.

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

Recompiling

When you've done editing it's time to recompile, using the command...
Code:
apktool b -insert folder name-
...and if you've edited your files correctly then it should compile with no errors and create a folder named dist in the decompiled folder along with a new apk.

Signing

Before using the new apk you will need to sign it, to do this you need two things from the original apk, the AndroidManifest.xml and META-INF folder, simply open the apk then drag and drop them to the dist folder, and you also need to extract the resources.arsc from the newly built apk so drag and drop that into the dist folder too. Then drag and drop all 3 back into the new apk, in WinRar it will give you the option to choose the compression method, and it's vital that you choose Store because if you don't then you WILL BOOT LOOP after restarting your Phone!


Alternatively you can use the following command...
Code:
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...
Quote:
Originally Posted by AndroidGraphix View Post

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

Quote:
DISADVANTAGES OF UNALIGNED APKs

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

The command for zipaligning is...
Code:
zipalign -v 4 framework-res.apk ZAframework-res.apk
...notice the "ZA", again that can be anything you want so long as it differs from the original name, I use ZA for an obvious reason, and again don't forget to rename it before using on your Phone.

And that pretty much covers command prompt editing, I have a few programs setup for different reasons but this is really my preferred method, feels like you have a bit more control over what's going on.


Getting APKs Back To Your Phone

It's just a reversal of how you got them off your Phone to begin with, use a file explorer and put your apk on your SD Card, then move it to the Phones System folder and change it's permissions to rw-rw-r, then move and replace it with the original. Most apps should continue to work but you will most likely need to reboot for changes to take effect. Or you can use adb to push and install them.

If all the above has worked correctly you should now have your modified apk installed with the changes you've made displayed on your Phone.

Program Editing

The following are programs that not only automate the process above but do a whole lot more too, so have a browse and give them a try.

Theming & Modifying

This is where the fun begins, once you've got setup to decompile your apks then obviously you're going to want to mod them, so here's a few pointers to clear up what seems like a daunting process to new comers...

To start with you'll probably just want to start with replacing images, so if that's all you want to do for now then here's a quick tip, you DON'T need to decompile or sign your apks!, simply edit and rename your replacment images on you computer, preferably using the same or similar dimensions then drag and drop them back into the right folders in the apk, always using Store as the compression method, but PLEASE NOTE; .9 pngs can be replaced in the same way, but if you want to edit them in Photoshop for example then you need DO need to decompile them.

A few things to note...
  • Smali code is real Developer territory, it's Matrix code to me , thankfully there's usually a guide to follow so you can simply copy and paste code without having to fully understand how it works, so don't fret about this.

    .9pngs are simply png images with a 1 pixel border. You can edit anything within that border but anything on or over will give errors when building. Unless you're creating an image from scratch then you can leave the border as it is, it's that simple! Sure there's a bit more to .9png editing but you can find a few links below that go into more detail about .9s and how they work.

    xmls are relatively simple and edited with Notepad++, much simpler to understand than smali and again, there's usually a guide to be found for most mods you may want to make yourself, but if you're feeling brave you can experiment with it when you have a basic understanding of how it works.

    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.

Links

Reading Material
U.I Modding
Text...
Statusbar...
Misc...
.9png Editing

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


Xposed Framework
Quote:
Originally Posted by rovo89 View Post
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)!
...
Advantages:
  • 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

CyanogenMod Theme Chooser
Quote:
Originally Posted by Annex1 View Post
CM10.1-THEME_BOOK

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.

ONLY THING FANCY IS MY FLASH BOOK
YOU MUST HAVE A FLASH PLAYER INSTALLED TO VIEW THIS!!!

- [GUIDE] HOW TO THEME CM10.1 - Animated Book
The Following 64 Users Say Thank You to XperienceD For This Useful Post: [ Click to Expand ]
 
XperienceD
Old
(Last edited by XperienceD; 19th April 2014 at 11:32 AM.)
#2  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Default ClockworkMod Recovery

Clockwork Mod (CWM)

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...
This is my Theme_CMW_Template.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 Ice Green ResMods 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.

If you feel something more should be added to this thread please feel free to suggest it.


Credits & Thanks:
And not forgetting @iBotPeaches and @Brut.all for making it possible with - [UTIL][Feb 02 2013] Apktool v1.5.2 - a tool for reverse engineering apk files
The Following 18 Users Say Thank You to XperienceD For This Useful Post: [ Click to Expand ]
 
XperienceD
Old
(Last edited by XperienceD; 8th July 2013 at 07:48 PM.)
#3  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Random Stuff...

Quote:
Originally Posted by ttibbetts83 View Post
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

http://my.opera.com/ubuntunerd1/blog...r-construction

ubuntu version of paint.net

http://pinta-project.com/

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

http://www.xaraxtreme.org/download.html

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

Quote:
Originally Posted by XperienceD View Post
Quote:
Originally Posted by cickii View Post
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...




Quote:
Originally Posted by XperienceD View Post
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...

Code:
<resources>
    <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>
</resources>
Simply change these two lines...

Code:
<item type="drawable" name="notification_item_background_color">#ff111111</item>
<item type="drawable" name="notification_item_background_color_pressed">#ff257390</item>
to...

Code:
<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 10 Users Say Thank You to XperienceD For This Useful Post: [ Click to Expand ]
 
jacknb1ack
Old
#4  
jacknb1ack's Avatar
Member
Thanks Meter 67
Posts: 39
Join Date: Mar 2013
Location: Yogyakarta

 
DONATE TO ME
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:	614
Size:	12.0 KB
ID:	1990170

Click image for larger version

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

Click image for larger version

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

Click image for larger version

Name:	Screenshot_2013-05-25-21-41-40.jpg
Views:	573
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

thanks,
jacknb1ack
 
XperienceD
Old
#5  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Quote:
Originally Posted by jacknb1ack View Post
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".
 
jacknb1ack
Old
#6  
jacknb1ack's Avatar
Member
Thanks Meter 67
Posts: 39
Join Date: Mar 2013
Location: Yogyakarta

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

thanks again.
 
XperienceD
Old
#7  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Quote:
Originally Posted by jacknb1ack View Post
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?
 
victorthe
Old
#8  
Junior Member
Thanks Meter 1
Posts: 23
Join Date: Jun 2013
Location: North Sulawesi
nice tutorial
 
jacknb1ack
Old
#9  
jacknb1ack's Avatar
Member
Thanks Meter 67
Posts: 39
Join Date: Mar 2013
Location: Yogyakarta

 
DONATE TO ME
Quote:
Originally Posted by XperienceD View Post
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

https://picasaweb.google.com/1172676...eat=directlink
 
XperienceD
Old
#10  
XperienceD's Avatar
Senior Member - OP
Thanks Meter 2329
Posts: 7,181
Join Date: Jul 2010
Location: Here =)
Quote:
Originally Posted by jacknb1ack View Post
yes .. thanks to you and all developers and themer here, i can finish my own customizing rom xD
Nice 1.

Quote:
Originally Posted by jacknb1ack View Post
Colourful.

Tags
apktool, decompile, guide, how to, theme
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes