Android OS Forum banner
1 - 11 of 11 Posts

·
Premium Member
Joined
·
28 Posts
How To Port Theme's
(Using Apktool, and Theme Porter)

Since there are some people out there willing to learn but not exactly able to with all of the convoluted information on the forums, I decided I'd start putting together a guide similar to other's to aid those trying to learn. Stay tuned as this is under construction!

All credit is due to original creators of the product's used in this process, without them there wouldn't be a reason for this guide
. Please be respectful of other's work, sometimes it's best to ask before attempting (if it is an original product) but at very least give credit and a link back.

What is porting?
  • Porting very basically is taking .png files and XML changes from one theme (typically created for a different model, but using the same resolution) and copying them into deodexed stock rom's such as EC10/EE19 Pick and Pack so that they can be flashed onto our phones and used with our framework and/or updated framework.
  • Sounds really easy, doesn't it? At first it will be cumbersome and frustrating, but after you've used the processes enough you will be able to snap these out in 30 minutes or less! The problem lies in the way these files are packaged, they are mainly just a .zip file that isn't compressed, however there is another layer to an .apk that you can only see once you've learned how to use tools such as apktool/apkmanager. The other tool we will use to aid us in this painstaking process is an application called Theme Porter, which essentially is a script that has been written that will do all of the legwork for us. Let's get started!
What will I need?
How to set up;
  • Begin by getting ThemePorter setup, you just need to unzip the download and that will be "theme porter" It is basically just made up of a few folders, and has a batch script that you will use to initiate the process. I just place mine on the desktop for easy access.
  • Secondly, get apktool downloaded and unzipped. place the apt folder somewhere where you can easily navigate to it through a command prompt. C: might be a good place if you want to save yourself some keystrokes.
  • Next just make sure you have notepad++ or another editor installed for use later.
  • Lastly, get 7zip installed so that you're able to open .apk and .zip files without actually extracting the files.
Where do I get my source files?
  • You can use any framework from any rom that can be decompiled correctly with apktool. This means when you decompile it, there are no errors and it generates a folder with the same name. Download the rom of your choice and save it (still zipped) somewhere on your desktop, and make an extra copy in case you mess up and overwrite the wrong files. You will ALWAYS use these in the NEW folder within theme porter, but we will get to that.
  • As for the theme you're trying to port, I usually use fascinate theme's, because it is basically a direct copy of our phone (Note: As of 2.2 they now have a Data on/off icon in their status pull down, where we have Silence, so this will often need to be taken care of separate from this process.) I've also recently started using Vibrant theme's, as these are also very similar - but there are tweaks with these too and I will try to cover them in the guide at some point. You may find others that will work too, at this point this is all I've had time to mess with. Either way, download the .ZIP file and also place it somewhere easy to access.
This is where it get's sort of difficult.
  • Stock ROM's have some differences to theme's that theme porter cannot handle for you. These are basically MOD's that may exist in the theme ROM and/or XML changes that have been made to alter text color's to accommodate the theme (black to white, white to black, etc.) These changes WILL NOT be ported over using theme porter and unfortunately also cannot be made AFTER using theme porter, so there is a certain process to go about this.
  • Now enter's apktool. Apktool is a script brut.all very kindly wrote to assist android developers in decompiling/recompiling .apk files without losing structure that normal compression software breaks. Basically there are two reasons you will need to take this step.
When;
  1. Editing Text Color- When choosing a theme to port you will need to pay attention to the screenshots the original poster has posted, as these will clue you in whether or not this needs to happen.

    The Pick and Pack rom is essentially still stock, as far as XML goes - so the text on menu's for example, will be Black text on a white background. If the theme you chose has something different, you will need to take this step so that the text is legible in the final theme.
  2. Adding accurate battery MOD- Also when choosing a theme you will need to take a look at the framework-res.apk file to determine if the themer has added the accurate battery mod. Essentially all this means is the XML and image's have been edited to show you each percentage of battery life vs. the stock one that only shows odd increments of 10/15/20.
    Open framework-res.apk with 7zip
    Navigate to res/drawable-hdpi (this also may be drawable-hdpi-v4 depending on your theme, I haven't quite figured out why this is)
    Scroll down until you see the status_battery icons near the bottom - if there are not images for every percentage - then no mod exist's and you can skip using apktool for this step.

How;

  • For either change you will follow this process to decompile To gain access to the XML/PNG files that contain these text values, we will need to decompile the framework-res.apk file from the rom.
  • Copy framework-res.apk from the rom and place in the APT folder created earlier.
  • Rename this to something shorter such as "FW.apk" for easier command lines
  • Start a command prompt (in windows 7 type "cmd" in the search bar within start menu)
  • Navigate to the APT folder, For example;
    Code:
    CD c:\Users\brandon\Desktop\apt
  • Type
    Code:
    apktool d FW.apk
  • This will decompile the .apk into a folder called FW within the APT folder, allowing you access to the files. I will cover the actual changes in a later post.
  • At this point you have the files in a folder and they can be edited how you see fit (should you choose to just edit the stock ones vs. actually porting already changed ones).

    You'll notice when examining the folder that there are quite a bit more files. Also, you will be introduced to the .9.png file type, which essentially is just a .png file that has some black lines embedded in the file to instruct android how to resize and reuse the image within the framework.

    Any edits made to these files must be made carefully, as to not alter the integrity of these black lines. When the file is recompiled, the lines will disappear but will be included (if you tried doing this without decompiling - your photo editor would nix these lines and android wouldn't know how to size them)
  • If all your edits were complete, you would then recompile the file through apktool. (I will continue with the theme porting guide in the next step, this is just a good reference point for these steps.)
    Type this into the command prompt
    Code:
    apktool b FW framework-res.apk
  • This would then create the framework-res.apk file in the APT folder, however there is an important step here. During this process the META folder is lost, and the AndroidManifest file is corrupted.
  • Delete the AndroidManifest.xml file from the new framework-res.apk
  • Copy the META-INF folder and the AndroidManfiest.xml file from the ORIGINAL framework-res.apk (now named FW.apk in this example) and place it in the new framework-res.apk using 7zip (do not extract the file, open the archive with 7zip.)
  • At this point, your framework could be ready for replacing in your theme.zip (will be covered later) with the edit's you've made Or if you're learning how to port theme's, continue reading.
 

·
Premium Member
Joined
·
28 Posts
Preparing for Theme Porter
  • Okay now that we have some of the side process out of the way, let's get back to the guide.
  • Determine if you need to make any XML edit's for battery or text color changes and perform them per the processes detailed below. If you do not need to make them, you may skip this step completely and move on to using theme porter.

Correcting Accurate Battery Mod Animations-
  • Follow this guide to make the changes to the framework to use the new charging animation images and will allow you to then use theme porter to swap the .png files
  • Decompile the framework-res.apk from the ROM download (I usually just rename this to EE19.apk or whatever the rom is i'm working with)
  • Decompile the framework-res.apk (I first rename the framework-res.apk file to NEW.apk (or whatever you wish) Note: It will typcially give you errors (unless it's theme'd correctly) but you're just after some code from a few .xml files so don't worry.
  • In the NEW folder Navigate to
    Code:
    \res\drawable-hdpi\<br />
    or<br />
    \res\drawable-hdpi-v4\
  • open the following file in notepad++
    Code:
    \apt\NEW\res\drawable\stat_sys_battery_charge.xml
  • Also open the same file within the EE19 decompiled folder
  • In the THEME xml file select all and copy
  • In the EE19 xml file, paste this replacing the text. Then save it overwriting the original.
  • At this point, the battery mod is done and the new .png files exist so that theme porter can do it's work (And the xml is there to make it works when it get's to your phone). If you don't have any text edits to make, you can recompile the apk (as stated in steps in first post) and move on to steps below (skipping the section on changing text).

Changing text colors-
  • If you have determined that the text in the theme is different from the rom framework (I.E. Text on notifications, menu's, etc.) then you will follow these steps to locate where these changes need to be made.
  • If you haven't already, decompile the framework-res.apk from the Rom.
  • Next, determine what text color edit's you need to make and then use this wonderful reference to determine which actual files those edit's correspond to.
  • Locate the file you need to edit in the decompiled folder, and open it with 7zip.
  • Typically removing the "inverse" reference on the color line will change it from black to white, or white to black and is the easiest/best way to alter colors in a ROM. (For a quick note, searching for "menu" in the styles.xml files located in /values/ will give you the items you need to change, watch for _bright references for the dividers, change those to _dark instead.
  • Once you are done making these edits, recompile the folder as stated in first post. And move on to using theme porter.

Using Theme Porter-PAY CLOSE ATTENTION HERE.
  • Now that you have the appropriate prep-work done, the easy part finally comes. (Hopefully)
  • Copy and paste the applications & framework-res.apk twframework-res.apk files from the THEME.zip into the appropriate folders within the OLD folder in theme porter.
  • Now copy and paste the same files that you copied from the theme.zip, now from the rom (EE19 for example) to the NEW folder in theme porter.
  • Once all files are in appropriate folders, run the Script.bat file in theme porter. Use a selection of "1" and press enter.
  • Theme porter will now copy all of the .png files from one .apk to the other (where the folder names are an exact match)

    NOTE:At this step, you may have issues where the images aren't brought over (This typically only effects the framework files and just depends on how the file was generated/edited). This can be detrmined by opening the .apk in 7zip and pulling out the res folder, where you can view the files (you will see if it's been changed or not) If it hasn't, you will need to make sure the folder within the Themed .apk's are the exact same as the ROM you're themeing and re-run the theme porter script. (meaning you need to add or remove the -v4 ending depending on where the previous themer placed the themed files)
  • If you're lucky, everything is done at this point and you can move on to packaging a flashable update.zip.

Packaging A Flashable Update.Zip
  • A flashable package is simply a .zip file (stored as "store" in 7zip, no compression) that is made up of META-INF and System folders. The META-INF folder is very important as there is a big difference between using one from a ROM (pick and pick) and a theme (NeonGT) You will need to download a theme and pull the META-INF folder out so that you can use it in your theme ports. This is to ensure you have the correct script (edify or ammend) typically now we're using edify so use one from one of the H57 theme's via baked_tator The system folder should contain two folders "framework" and "app" each of which will hold the respective .apk files you have been working with. (but could also contain a "Media" folder for changing bootanimation.zip files, basically any files within the folder structure you create (matches the system structure) will be replaced when flashed. So be careful not to include things I haven't listed here unless you know what you're doing. And be sure to test these things before even thinking about a release.
  • Create the following folder that can be re-used with any new theme port, it's the easiest way to keep things organized and not lose track of files.
  • Create a new folder on your desktop called New Theme
  • Within that folder paste in the META-INF folder from another EE19 theme.
  • Create a new folder called "system"
  • Open system and create two new folders "app" and "framework" (and "media" if you are including the bootanimation.zip from the theme (which typically will work on our phone)
  • Place approprate files from the NEW folder within theme porter into these folders, respectively
  • Back up so that you see the META-INF folder and System folder, select those two, right-click and select "add to archive" in the 7zip menu.
  • Name the file "EE19 ThemeName VX.zip" and select "Store" for the method
  • Drag this to your desktop and this will be what you will place on your SD card for flashing.
  • Test the theme thoroughly to make sure everything ported over and everything still works (make sure to test USB, even color XML edits can cause odd issues) and get help from others to make sure the bugs are out.
  • If you run into issues, check the next post for possible resolutions.
  • BE SURE TO CREDIT THE PROPER CREATORS!!! I can't express this enough, I have a format for the way I do release posts, feel free to copy it if you'd like but either way make sure you make it known that it's not your work!
 

·
Premium Member
Joined
·
28 Posts
Common Issues:
  • Images do not transfer to new framework.apk files.

    (typically the applications all have the same folder names, so no problems occur here.)
    As stated in the guide, all folders within each res folder within each .apk file used in theme porter must have exact matching folders/files for the .png to actually transfer. If it's been edited with apktool, it typically has the -v4 extension.

    Troubleshoot your issue by opening the resulting .apk file in 7zip and comparing to the downloaded theme file in 7zip. You may have to pull the res folders out and look that way to actually see which images didn't transfer.

    First thing to check is the folder names within the res folder, if the rom folder's names are "drawable-hdpi" and "drawable-land-hdpi" and the theme has "drawable-hdp-v4" then you need to remove the -v4 from those folders and run theme porter again.

    NOTE: I've also run into situations where both folder's existed in the .apk file, meaning both drawable-hdpi and drawable-hdpi-v4 folders were there, but only one actually had the themed .pngs. In this case it was the drawable-hdpi folder that had the themed ones, but I needed it to be -v4, so I deleted the existing -v4 folders and renamed the others to -v4 - this also slimmed the rom because you really don't need the extra folders/files (nor wan't them!)

    Some times icons don't exist on other phones, or they are completely different icons. I.E. with 2.2 fascinate theme's the Silence icon does not exist and therefore would need to be pulled from another theme or created to be fixed. This can be done with 7zip, no need to decompile the file if you're just swapping .png files (in the final framework-res.apk .

    [*]Problems after testing theme.

    This has happened to me on all sorts of levels;

    Problems Restoring - Sometimes after testing theme's you'll go to restore and things will not be right when you boot, FC's and whatnot. Best case scenario you can restore to a vanilla restore (meaning your rom + any app's you wanted, but no theme's) or just flash your rom to fix.

    Problems with icon's not being correct on a restore or a flash.
    Same as above, sometimes things just go awry when you're flashing theme on top of theme, so i'ts best to start from the rom. Make a restore point with your rom + all your apps, then you can always go back to it and flash your day to day theme - this will give you the least trouble.

    Phone stuck in airplane mode, setting is disabled.
    I had this happen to me randomly once, no idea why but if you do run into this the only thing that fixed it for me was an odin back to a full build. No restore or flash would fix it. Typically your problem should be solved with a fresh flash of your rom, but sometimes going to a full build with odin is the only way.

FAQ:
  • Post them and we'll get them answered and edited in here. So far I've tried to cover everything I knew of in the guide
    .
  • Reserved
  • Reserved
  • Reserved

Other Resourcs:
 

·
Premium Member
Joined
·
595 Posts
i used it!!!!
 

·
Premium Member
Joined
·
28 Posts
Discussion Starter · #9 ·
akellar said:
Awesome work sir. What the heck are you doing up at 330 AM writing theme guides though?!?

Edit: LOL apparently going to settings and changing my time zone helps, huh?
LMAO, yea I was going to say "I wish I could be!"
 

·
Supporting Member
Joined
·
170 Posts
This is a very nice guide. Though does anyone know of a guide like this for linux been looking everywhere and just can't seem to find one.
 

·
Android Apprentice
Joined
·
59 Posts
Was wondering if anyone has tried using this same guide to port themes from 2.2 to 2.3?
I just tried this and got a stuck Samsung screen. I even tried just adding the new framework-res to the already working rom and the same thing happened.
When themeporter does it's work could it be messing up some of the files?
 
1 - 11 of 11 Posts
Top