Monday, October 22, 2012

Creating a basic custom rom

A Dummies Look on Custom Roms
Topics covered are as below :
OK lets get started to learn about the basics

  • Stock Rom
  • Custom Rom
  • Rooting
  • ADB
  • Recovery

Creating a custom rom

  • Custom-rom-creator-studio
  • Android Kitchen
  • Modify/Extract an app
  • smali/baksmali to disassemble the dex files
  • Modifying framework-res.apk
  • UOT Kitchen

When we generally talk about ROM, it means Read Only Memory. However in the Android developer circle it means an actual custom image of the OS installed in the ROM area of your smartphone.

A stock ROM is the version of the phone's operating system that comes with your phone when you buy it.
custom ROM is a fully standalone version of the OS, including the kernel (which makes everything run), apps, services, etc - everything you need to operate the device, except it's customized by someone in some way.
These ROMS are specifically aimed at the consumer who want the advantages of rooting, but without completely changing the basic operating system that comes with the phone. Every phone comes with a stock ROM. It’s not bad, but if you took the time to root your phone then you are probably looking for some extra features.

Android rooting is the process of allowing users of smartphonestablets, and other devices running the Android mobile operating system to attainprivileged control (known as "root access") within Android's subsystem. Rooting is often performed with the goal of overcoming limitations thatcarriers and hardware manufacturers put on some devices, resulting in the ability to alter or replace system applications and settings, run specialized apps that require administrator-level permissions, or perform other operations that are otherwise inaccessible to a normal Android user. Rooting is analogous to jailbreaking devices running the Apple iOS operating system. On Android, rooting can also facilitate the complete removal and replacement of the device's operating system, usually with a more recent release of its current operating system.

ADB stands for Android Debug Bridge. It comes as a part of the standard Android SDK, which you can grab here. Basically, it provides a terminal-based interface for interacting with your phone’s file system. Since Android platform is based on Linux, command-line is the only way to obtain and manipulate root access often required to perform certain advanced operations on your device using root access.
While these things can be done directly on the device itself using some terminal emulator, it will be rather difficult to execute complex commands on such a small screen. ADB provides the bridge between your machine and your computer.
Installing ADB and drivers look here
Turning on ADB
Go to Menu > Settings > Applications > Development > USB Debugging
Learn basic ADB commands

adb push - sends a file to the phone over ADB thru USB - adb push c:\test.apk /sdcard/test.apk

adb pull - receives a file from the phone over ADB thru USB - adb pull /system/app/Test.apk c:\Test.apk

adb shell - starts a shell connection with the phone

adb reboot - restarts the phone

adb reboot recovery - restarts the phone into recovery

adb reboot bootloader - restarts the phone into the bootloader (white screen)

adb remount - remounts the file system

adb install <path to .apk file> - installs an application - adb install c:\swype.apk

adb uninstall <package name> - uninstalls an application - package name is usually in the format,

Learn basic Linux commands to run through ADB shell

cd - changes directories - works through stock android toolbox - cd /system/app

ls - lists all files in the directory - works through stock android toolbox - ls /system/app/

cat - copies files - works through stock android toolbox - cat /system/app/Test.apk > /sdcard/Test.apk

rm - removes files - works through stock android toolbox - rm /system/app/Test.apk

mv - moves files from one location to another - works through stock android toolbox - mv /system/app/Test.apk /sdcard/Test.apk

cp - copies files - functions similar to cat - uses busybox installed by the into recovery mode - cp /system/app/Test.apk /sdcard/Test.apk

mount - loads the file system (usually auto loaded except sometimes in recovery) - mount /dev/block/mtdblock4 /system

unmount - unloads the file system - umount /system

For more commands and description look here

What is recovery?  In Android, recovery refers to the dedicated, bootable partition that has the recovery console installed.  A combination of key presses (or instructions from a command line) will boot your phone to recovery, where you can find tools to help repair (recover) your installation as well as install official OS updates.  Because Android is open and has the recovery source code available, building a customized version with more and different options is relatively easy as well.  Let's look at both options.
The stock recovery is pretty limited, but that's by design.  Its main purpose is to delete all user data and files, or to perform system updates.  Normally, both these operations are started from the running Android system, or you can do things manually and boot right into recovery yourself.  When you tell your phone to do a factory reset, recovery is what boots up and erases the files and data.  Likewise with updates -- when we restart to install an official OS update, it's done in recovery.  Recovery is also where we go to manually install official OS updates we've downloaded from the Internet.  It's very useful, but limited.
Custom Android recoveries offer much more.  They have been coded to allow for backup and restore functions, selective deletion of data so you don't have to wipe everything, and modified to allow update packages that have not been digitally signed by official sources.  You also can mount various partitions so that you can copy files to the SD card without having to remove it or reboot into Android. Anytime you see someone mentioning Clockwork or Amon Ra, they're talking about custom recoveries.  Because of the extra functionality built in, they are a pretty important tool for folks who want to hack their Android phone or tablet.  Recoveries aren't as pretty as a custom ROM and don't get the same love from users and bloggers that custom builds of Android do, but in the end they're even more important. Without them none of this custom ROM stuff would be possible.
The most famous ClockWorkMod (CWM) recovery
ClockworkMod Recovery is a secondary recovery option for Android devices made by Koush. It is based off the eclair recovery image. Features include Nandroid backup, adb shell, advanced options (ignore asserts and signature checks), and file browser for choosing update.zips
It is also known as CWM, clockwork, CW recovery

Porting CWM recovery for MT65xx phones

Basic Clockwork Mod Recovery Menu

Reboot system now (Self explanatory )
Apply update from SDcard. (when you connect your device to your computer it will show up as tablet. The SDcard that cwm refers to is simply your device storage. Always make sure to copy install.zips to the root directory of your tablet storage.) You use this when applying an update for a specific ROM if that is what the ROM developer says.
Wipe Data/ Factory Reset You should always do this before you install a new ROM or if you are having minor issues with your device.
Wipe cache partition Think of this as the lite version of whats above . If you do above though it doesn't hurt to do this too.
Install zip from SDcard Use this to install new ROMs.
Back up and Restore
Mounts and Storage use this to connect your device to your computer when in recovery mode. It is also possible to transfer files to your device while in this mode.
Advanced What you are interested in here is something called dalvik cache, you want to wipe this too before installing any new ROM
Power off

Custom rom creator studio

A project/solution based development environment for creating customized android roms.

For Windows/.NET Framework 4.0 and Linux/Mono 2.10.2
The version for Mono might work on OSX/Mono.

It is using apktool and smali/baksmali to do the hard work.


Open files from command line and associate file types(.rssln, .rsproj and .apk)(windows only)
ApkViewer, shows content of apk files (windows only)
Compare content of apk and jar files with older versions.
Text editor
Automatically discovers boot class paths
Decompiling classes
Recompiling classes
Decoding resources
Encoding resources
Optimizing png files (windows only)
Signing apk files
Excluding/Including files

Android Kitchen is simple yet very powerful tool developed by dsixda, a developer from xda developers forum, made to help making and modifying Android ROMs.
Although dsixda stopped developing this tool some time ago, Android Kitchen is still one of rareAll In One tools with which you can do things you woud probably do with a lot of separate tools

Android Kitchen is a Linux Shell Script but it can be also launched on Windows by using Cygwin.
    • You can extract ROMs from following extentions: .zip, .img (nandroid backup) .app (huawei update format)
    • You can unpack and repack boot.img (for changing kernel…)
    • You can root stock ROM
    • Support for app2sd
    • Deodexing stock ROM
    You can find whole set of features on xda forum

    The android kitchen software to do the basic functions to my ROM like adding root access and such.

    The easiest way to do this is to build a Linux VM but the kitchen can also be run from windows using cygwin.

    Check this post here:

    It has a download for the kitchen software as well as detailed guides on how to use it.

    From clockworkmod perform a nandroid backup of your phone and then copy the system.img and boot.img files into the kitchens original_update folder and then create your working folder from that.

    (If you go through the guide on the kitchen thread you'll understand what I mean)
    After you have your working folder ready you can go through the various kitchen options to add root, superuser & busybox, deodex all your apps, etc, etc.
    You will then want to go through your /system/app folder and remove any apps you don't want and also move and add apps to /data/app for ones that you can run from the user partition (do not move the market out of /system/app).
    There are several guides around of what the system apps do and be carfeul what you remove as some are very important for functionality.

    Check this thread for some basic steps of the things you will want to do to start with.

    To modify/extract an app

    If you want to make some modifications of apps and functionality you will need to get a bit deeper into things.

    You can use tools like apkmanager to decompile the apk files so that you can edit them and recompile.
    To change the interfaces and such you will want to do this to files such as /system/framework/framework-res.apk and /system/app/SystemUI.apk.
    The interfaces are basically made up of a series or xml files that define where everything is and the images that are being displayed.

    There is also a website called UOT Kitchen that can be used to modifiy the interface for you.

    You just need to upload your framework-res.apk and SystemUI.apk and choose the look you like and it will alter them for you.
    I used it to modify the interfaces I used but unfortunately it doesn't work on our phones too well because the dual sim features use different images and relations and the kitchen can't modify them properly. They also don't look so good with the colored sim backgrounds our phones use so I had to modify the images and recreate the interfaces manually for most things but it should work pretty well for any other phone type.

    To go further into coding changes you will need to learn how to use smali/baksmali to disassemble the dex files that are stored in the apps.

    When you use baksmali to disassemble a file it will be a plain text representation of the dalvik code which is kind of a cross between assembly code and java.

    As an example of how to work with that see this guide of how to modify your boot menu options. Like adding recovery option when pressing the power button.

    Depending on what you want to do to your ROM depends on how much you want to delve and learn but luckily there is plenty of information out there since it is an open source platform.

    1 comment: