FORUMS
Remove All Ads from XDA

[Guide/Reference] APK Modding & Theming Thread... {26/10/16}

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

The greatest thing about Android and the main reason that will keep me a die-hard Android fan is that you can change just about every element of the U.I, and it’s quite easy to do too. I created this thread to share with you what I've learned during my time here at XDA, and to be a reference of information related to .apk modding and Android theming.

Some Requirements:
  • A Rooted Phone.
  • A BACKUP OF YOUR PHONE!
  • Java SE Development Kit – Apktool etc are .jar files.
  • 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 and creativity.
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, Smali/Baksmali, ADB along with sign.jar and a text file with all the commands you need.
Download APKTool_2.2.1.zip to a location of your choice, preferably the C:\ drive which will give you a folder to work from.

This thread will cover the following…
  • Pulling files from your Phone.
  • Deodexing
  • .apk De-compiling
  • .apk Recompiling
  • .apk Signing
  • .apk Zipaligning
  • Pushing Files to your Phone
  • .9 images
  • CWM zips
  • +More
...in an easy to follow manner that will have you theming your own .apks in no time.

Quick Tips;
  • .apk files when on your computer can be browsed like .zip files, 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 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.


Once your folder is setup, this is how mine currently looks...



…java and other tools installed, you need to get any apks you want to theme off your Phone and there are numerous ways to do this. To use adb commands to pull files to your computer 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...
Code:
adb pull /system/ Z1C_368
...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 and the commands to do that are…
Code:
adb pull /system/app/ Z1C_368 app
adb pull /system/priv-app/ Z1C_368 priv-app
adb pull /system/framework/ Z1C_368 framework
...or to pull individual files...
Code:
adb pull /system/framework/framework-res.apk
...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.

“Deodexing is basically repackaging of these APKs in a certain way, such that they are reassembled into classes.dex files. By doing that, all pieces of an application package are put together back in one place, thus eliminating the worry of a modified APK conflicting with some separate odexed parts.”What Is Odex And Deodex In Android
The tool I use is this - [Tool/Utility] JoelDroid Lollipop Batch Deodexer. I only deodex the apps I need to theme rather than run a fully deodexed rom.


Before proceeding you need to install your framework-res.apk and SemcGenericUxpRes.apk/twframework.apk, which will put two apks at C:\Users\your-pc-name\AppData\Local\apktool\framework which become the resources apktool uses to work its magic. The two commands to install your resource apks are...
Code:
apktool if framework-res.apk
apktool if SemcGenericUxpRes.apk



The command for decompiling is...
Code:
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 framework, 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. It’s at this stage that you can now begin to modify .9 images and xmls to create the desired look or mod you’re after. See below for a list of guides and tutorials to help you theme your phone.


Once you've finished making your mods you need to recompile your apk using the following command...
Code:
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. To sign stock system .apks 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. For 3rd party apps you can use the following command...
Code:
java -jar signapk.jar testkey.x509.pem testkey.pk8 Chrome.apk ChromeS.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 ChromeS.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


- Noobs guide to signing an APK with a Private Key
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
Move your new signed apk into your APKTool folder, you can overwrite your original if you want, and use the following command...
Code:
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 system, and the command for that is...
Code:
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...
Code:
adb push D:\Xperia\Z1C_368\APKTOOL\framework-res.apk /system/framework
...yet for the SystemUI it's...
Code:
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...
Code:
adb reboot
...your Phone will restart and if you've done everything right your new mods should be displayed, happy days.

And that's it for how to use command prompt for modifying apks.


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

There are a number of programs you can use that automate the above processes, the three best/most popular GUI programs are...

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




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



I hope after reading this explanation you're not 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...


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

So now you know how to prepare an apk for editing you’re going to want to theme it obviously, and the following links will help you with that.
Framework
SystemUI
Settings
Phonebook/Messaging
Misc



Quote:
Originally Posted by sykopompos

What is Layers?

Layers is a extension of runtime resource overlay.
RRO is a framework created by sony for use as a way for them to create xperia themes but also for internal quick prototyping.
...
So what is a Layer?

A layer is what we call our themes. A Layers theme is a collection of overlays
...
So how does it work?

What a overlay does is that it looks for a string in the the resources and replaces it during loading into the system.
For a way better and more in depth explanation see sony's blog post about how rro works

http://developer.sonymobile.com/2014...-code-example/

Quote:
Originally Posted by krazie1

LAYERS GUIDE
How To Make a Overlay APK by Brian Gill https://plus.google.com/+BrianGill55/posts/GhsDQESpfDN
Layers Overlay System How To by Tom Lichti https://plus.google.com/+TomLichti/posts/9o72Du9Whwc

LAYERS COLOR PALETTE
Google Material Design Guidelines http://www.google.com/design/spec/style/color.html#

LAYERS TOOL
Layers Project Generator Tool http://forum.xda-developers.com/andr...22015-t3018798

LAYERS MANAGER APP
Official Layers Manager App 3.0 https://play.google.com/store/apps/d...dlayersmanager UPDATED

LAYERS VIDEO TUTORIALS
Tutorial for applying RRO Overlays on any RRO based rom by AVKAppReviews https://www.youtube.com/watch?v=v57xcwFVaqo
Layers Manager App (Applying Layers Made Easy) by AVKAppReviews https://www.youtube.com/watch?v=kH60lD8vu_Q
Layers Manager App by MJB Review https://www.youtube.com/watch?v=yU9zsX4Jxuc




Quote:
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)!
...
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



Quote:
Originally Posted by Annex1

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 25 Users Say Thank You to XperienceD For This Useful Post: [ View ] Gift XperienceD Ad-Free
25th May 2013, 03:22 PM |#3  
Reserved.
The Following 12 Users Say Thank You to XperienceD For This Useful Post: [ View ] Gift XperienceD Ad-Free
25th May 2013, 05:31 PM |#4  
jacknb1ack's Avatar
Member
Flag Yogyakarta
Thanks Meter: 71
 
More
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:	1118
Size:	12.0 KB
ID:	1990170

Click image for larger version

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

Click image for larger version

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

Click image for larger version

Name:	Screenshot_2013-05-25-21-41-40.jpg
Views:	1073
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
The Following User Says Thank You to jacknb1ack For This Useful Post: [ View ] Gift jacknb1ack Ad-Free
26th May 2013, 09:46 AM |#5  
Quote:
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, 04:01 PM |#6  
jacknb1ack's Avatar
Member
Flag Yogyakarta
Thanks Meter: 71
 
More
great, i think i've clicked all the link in ur post ... but looks like i've missde some link xD ...

thanks again.
19th June 2013, 12:08 AM |#7  
Quote:
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, 06:50 AM |#8  
Junior Member
Flag North Sulawesi
Thanks Meter: 1
 
More
Thumbs up
nice tutorial
20th June 2013, 12:27 PM |#9  
jacknb1ack's Avatar
Member
Flag Yogyakarta
Thanks Meter: 71
 
More
Quote:
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

https://picasaweb.google.com/1172676...eat=directlink
20th June 2013, 06:17 PM |#10  
Quote:
Originally Posted by jacknb1ack

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

https://picasaweb.google.com/1172676...eat=directlink

Colourful.
Post Reply Subscribe to Thread

Tags
apktool, decompile, guide, how to, theme

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

Advanced Search
Display Modes