- First of all, you don't actually need to be a "developer" as such to be able to theme and you don't need to know or have to learn lots of code either.
- Secondly, EVERYTHING you need to know and need to use to modify an .apk is in this thread!
- Apktool, which can decompile an .apk allowing you to modify your own .xmls and .9png images, which is what this thread will focus on.
- Substratum, RRO, Xposed essentially overlay themes or mods.
Overlaying doesn't cover every element so falls short of a one stop solution for being able to fully theme a ROM and is a bit more complex and/or restrictive in it's approach.
We also need the ADB files from the SDK Platform and a sign.jar but to simplify this as much as possible I've made a zip for you to download which contains Apktool and everything else you need that you haven't got from the list above.
Download APKTool_2.2.4.zip to a location of your choice, preferably the C:\ drive which will give you a folder to work from. To keep the folder updated you can download the updated files from the retrospective thread/sites and simply replace them in the folder.
- Getting apks from a ROM
- .apk De-compiling
- .apk Recompiling
- .apk Signing
- .apk Zipaligning
- Pushing Files to your Phone
- .9 images
- Vector Drawable
- .apk files can be browsed like .zip files so set your zip program as the default for handling apks which will makes things much easier.
- If all you want to do is edit images then you don't 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.
- Restoring files if you mess up is easier and quicker with a CWM.zip, especially if you're modifying 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.
- Getting apks from a ROM:
1. The simplest method is to extract your phones whole system from an unofficial update file from xda, whatever format that may be in depends on your device. I extract the whole system with every new update before doing anything because it gives me a backup of stock files which I can also copy and deodex to be themed.Depending on your method you should now have a ApkTool_2.2.4 folder with another folder named 206_system for example in it. The only folders we need at this point are app, priv-app and framework which we need for the next step.
2. Use adb commands to pull files to your computer, to do that we need to open a command prompt window (hold the shift key then right click your mouse in the Apktool folder and select "open command window here").
The command to pull your whole system is......you can choose something other than XC_206 as your folder name but it will create that folder in your Apktool folder. Alternatively, you can just download individual folders and the commands to do that are…Code:adb pull /system/ XC_206...or to pull individual files...Code:adb pull /system/app/ XC_206 app adb pull /system/priv-app/ XC_206 priv-app adb pull /system/framework/ XC_206 framework3. Use a root explorer on your phone to copy files to your SD and then to your PC.Code:adb pull /system/framework/framework-res.apk
“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 AndroidThe tool I use is this - [Tool/Utility] JoelDroid Lollipop Batch Deodexer. To save a lot of time I only deodex the apps I'm going to use because it removes the process of having to mess about with smali and baksmali, plus YOU DON'T NEED TO DEODEX YOUR WHOLE FW!, depending on the apk and/or the mod you want to make you don't even need to deodex.
So now you should have a folder named system full of deodexed apks that are ready for playing with.
Before proceeding you need to install your framework-res.apk and depending on your FW possibly another apk if there is one in the framework folder, which will put one (or two) apks at C:\Users\your-pc-name\AppData\Local\apktool\framework The two commands to install your apks are...
The command for decompiling always begins the same, apktool d then simply change it for the name of the next apk you want to modify. To decompile the framework-res.apk the command is...Code:apktool if framework-res.apk apktool if SemcGenericUxpRes.apk
...this will create a folder named framework-res and 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. In this folder you'll find a couple of folders but the one we want is the res folder. First glance of a decompiled res folder can be overwhelming, 1541 folders in my framework but we only need to focus on a handful and it's generally the same in every apk...Code:apktool d framework-res.apk
...you may need to delve into others sometimes but it's very rare that I've had to.
- drawable-xhdpi-v4 (depending on your device)
- Once you've entered a few commands so long as you leave the cmd window open you can quickly scroll back through them using your arrow keys.
...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.Code:apktool b framework-res
For 3rd party apps you can use the following command...
...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.Code:java -jar signapk.jar testkey.x509.pem testkey.pk8 Chrome.apk ChromeS.apk
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...
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. - SOURCEMove your new signed apk into your APKTool folder, you can overwrite your original if you want, and use the following command...
...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 back to the original again before you use it.Code:zipalign -f -v 4 framework-res.apk ZAframework-res.apk
- Pushing Files to your Phone:
...then we need to mount the system before we can install our modified apk and the commands for that are...Code:adb push SystemUI.apk /sdcard/SystemUI.apk
The prefix will then change to the $ signCode:su
...then to install your apk...Code:mount -o rw,remount /system
If any of that fails you could try 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.Code:dd if=/sdcard/SystemUI.apk of=/system/priv-app/SystemUI/SystemUI.apk
- .9 pngs:
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
- 9compiler - batch process for themers android
- Vector Drawable:
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability. It can be scaled without loss of display quality, which means the same file is resized for different screen densities without loss of image quality. This results in smaller APK files and less developer maintenance. You can also use vector images for animation by using multiple XML files instead of multiple images for each display resolution.- developer.android.com/guide/topics/graphics/vector-drawable-resources
Vector drawables obviously serve a purpose but are a pita imo for themers as they are a lot more difficult to edit and achieve the look you want.
Using my power menu to illustrate the issue, Power off, Restart and Take screenshot icons are vector drawables but the Record screen icon is a png...
...as you can see the Record screen icon is significantly bigger and ruins the look of my power menu, to over come this I have two options.
1. Learn how to edit vector drawables and create a new icon.
2. Replace the vector drawables and use pngs.
The latter to me is preferable because I already have images that I've been using for the last few years and want to continue using, to do so I need to replace the code in the relevant xmls to point at images...
Vector drawable code...
<?xml version="1.0" encoding="utf-8"?> <vector android:tint="?colorControlNormal" android:height="24.0dip" android:width="24.0dip" android:viewportWidth="24.0" android:viewportHeight="24.0" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#ff000000" android:pathData="M13.0,3.0l-2.0,0.0l0.0,10.0l2.0,0.0L13.0,3.0zm4.83,2.17l-1.42,1.42C17.99,7.86 19.0,9.81 19.0,12.0c0.0,3.87 -3.13,7.0 -7.0,7.0s-7.0,-3.13 -7.0,-7.0c0.0,-2.19 1.01,-4.14 2.58,-5.42L6.17,5.17C4.23,6.82 3.0,9.26 3.0,12.0c0.0,4.97 4.03,9.0 9.0,9.0s9.0,-4.03 9.0,-9.0c0.0,-2.74 -1.23,-5.18 -3.17,-6.83z" /> </vector>
<?xml version="1.0" encoding="utf-8"?> <bitmap android:src="@drawable/ic_lock_power_off_alpha" xmlns:android="http://schemas.android.com/apk/res/android" />
Vector drawable code...
<?xml version="1.0" encoding="utf-8"?> <vector android:tint="?colorControlNormal" android:height="24.0dip" android:width="24.0dip" android:viewportWidth="24.0" android:viewportHeight="24.0" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#ff000000" android:pathData="M12.0,4.0L12.0,1.0L8.0,5.0l4.0,4.0L12.0,6.0c3.9,0.0 7.0,3.1 7.0,7.0c0.0,3.9 -3.1,7.0 -7.0,7.0l0.0,2.0c5.0,0.0 9.0,-4.0 9.0,-9.0C21.0,8.0 17.0,4.0 12.0,4.0z" /> <path android:fillColor="#ff000000" android:pathData="M5.0,12.9C5.0,11.0 5.8,9.2 7.2,7.9L5.8,6.4C4.0,8.1 3.0,10.5 3.0,12.9c0.0,4.0 2.7,7.6 6.5,8.7l0.5,-1.9C7.1,18.8 5.0,16.1 5.0,12.9z" /> </vector>
<?xml version="1.0" encoding="utf-8"?> <bitmap android:src="@drawable/ic_lock_restart" xmlns:android="http://schemas.android.com/apk/res/android" />
Vector drawable code...
<?xml version="1.0" encoding="utf-8"?> <vector android:height="24.0dip" android:width="24.0dip" android:viewportWidth="24.0" android:viewportHeight="24.0" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#8a000000" android:pathData="M5,5l4,0l0,-2l-4,0l-2,0l0,2l0,4l2,0l0,-4z" /> <path android:fillColor="#8a000000" android:pathData="M19,3l-4,0l0,2l4,0l0,4l2,0l0,-4l0,-2l-2,0z" /> <path android:fillColor="#8a000000" android:pathData="M5,15l-2,0l0,4l0,2l2,0l4,0l0,-2l-4,0l0,-4z" /> <path android:fillColor="#8a000000" android:pathData="M19,19l-4,0l0,2l4,0l2,0l0,-2l0,-4l-2,0l0,4z" /> <path android:fillColor="#8a000000" android:pathData="M16,13l0,-2l-3,0l0,-3l-2,0l0,3l-3,0l0,2l3,0l0,3l2,0l0,-3l3,0z" /> </vector>
<?xml version="1.0" encoding="utf-8"?> <bitmap android:src="@drawable/semc_ic_dialog_screenshot" xmlns:android="http://schemas.android.com/apk/res/android" />
...and finally my desired end result...
XML 101 - XML Modding Made Easy!
If you're modding Android, eventually you're going to have to edit some XML.
Want to center the clock in your statusbar? Rearrange the icons in your navbar? Change the layout of your notification screen? Get rid of a carrier label? Change the colour of some text?
Then you need to edit some XML files.
And you might not have any idea how...
Well, don't worry. The purpose of this thread is to show you just easy XML-editing can be. Once you've read it, you'll be one step closer to being an XML expert!
This guide is meant for noobs, experienced modders and everyone in between. Hopefully everybody can learn something..
Here's what this thread has to offer so far:
- Introduction (This Post)
- How To Delete A Line (Yes, Really)
- Some Useful Codes To Know
- How To Change The Colour Of The Status Bar Clock
- How To Put An Invisible Softkey In The Status Bar
- How To Center The Clock In The Status Bar...Part 1
- How To Center The Clock In The Status Bar...Part 2
- Centering The Clock In Xperia KitKat
- android:layout_gravity, android:gravity AND android:layout_weight
- Do NOT Edit "public.xml"!!
I also encourage others to post guides as well:
- How To Remove "am/pm" From The Clock On Pre-4.2 Roms (by @KronicSkillz)
- How To Swap The Notification And Status Bar Icons (by @Anmol0022)
- How To Hide A Centered Status Bar Clock When A Lollipop Device Is Locked (by @S0bes)
- @Diamondbacks - Virtuous Ten Studio
- @Ticklefishs - Tickle My Android
- @BDFreaks - Advanced ApkTool
- @mDroidds - StudioAndroid # Automize everything!
Quick Tip; Use VTS to edit certain xmls because it gives you a preview of any hex colour code and has a built in editor too which makes finding and changing colours a breeze.
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. I've posted a few links to different tutorials in the next post that you can use as a reference to theme your own phone, while the versions of Android change the methods and code are pretty consistent but you will have to adapt from time to time, but that's how you learn, refine your skills and become able to pass on your knowledge back to the xda community in the form of guides themes and mods.