Odex & Deodex demystified

As you might know Android is based on Linux & most users are coming from a Windows background. Every new Android user gets a little overwhelmed with new terminology. This is why we did this article-
>> The definitive Android cheat sheet/Glossary

One very common term is ‘odex & deodex’ which is mentioned in custom ROMs and firmware specs. Most users fail to understand what these terms actually imply

In this article, we’ll explore the use of odex and deodex  files and its implication to you.

Odex Files

Stock android implements an odex file structure. For most system apps (.apk file) and framework files (.jar) there is a corresponding .odex file. For eg.

/system/app/message.apk
/system/app/message.odex
/system/framework/com.mobisystems.android.jar
/system/framework/com.mobisystems.android..odex

All apps on your device are packaged as .apk files. These files are compiled from google source code and can interchangeably be viewed as a compressed folder (like a .zip or a .rar). Similarly most framework components are packaged as .jar files (Java Archive) which again can be compared to a .zip or a .rar.

Android OS uses a Java-based virtual machine for running applications, called the Dalvik Virtual Machine. When the android OS runs your apps or utilize its framework components, it has to parse (read/interpret) the cache used by this virtual machine (referred to as Dalvik-cache) held within the .apk or.jar files. What the odex file structure aims to do, is to expedite this process by utilizing another file (.odex file) to compliment every.apk file (and .jar file). The odex file includes the dalvil cache in uncompressed format so that the android can quickly interpret the important information before parsing through the rest of the data held within the compressed .apk/jar files. Now, when an Android-based system is booting, the davlik cache for the Davlik VM is built using these .odex files, allowing the OS to learn in advance what applications will be loaded, and thus speeds up the booting process.

Android applies this technique by default to all the system applications.

However, this makes hacking and modifying those apps difficult because parts of the apps have been extracted to another location. Theming requires a modification to .apks. The image files (.pngs) held within the pngs are replaced with different ones and it is impossible to theme an application if it exists as two files.

Deodex Files

A deodexed or .dex file contains dalvik cache for an app and it is stored inside the .apk. DeOdexing is the process of re-bundling the .odex files back into  .apk/.jar files, so that now all of the data is included in the .apk files necessary to run your applications without the presence of .odex files. The .odex are reassembled into classes.dex files. The classes.dex is optimized by the package manager on first use, and ends up in /data/dalvik-cache. It becomes possible to modify any application package without conflicting with the operating system’s execution environment.

Developers of custom ROMs always choose to deodex their ROM packages, since it allows them to modify various .apk and  makes theming possible for end users. The main point was to deodex services.jar so that you can change all text to different colors (such as the clock color to white) but to deodex services.jar, you need to deodex everything.

To summarize:

A deodexed or .dex file contains dalvik cache for an app and it is stored inside the .apk. “System” apps have the DEX optimization performed ahead of time. The resulting “.odex” file is stored next to the APK, the classes.dex is removed from the APK, and the whole thing works without having to put more stuff in your /data partition.

Advantages/Disadvantages/Implication:

The advantage of deodexing is in modification possibilities i.e. it makes theming possible.

On the other hand, since the .odex files were supposed to quickly build the dalvik cache, removing them would mean longer initial boot times. However, this is true only for the first ever boot after deodexing, since the cache would still get built over time as applications are used. Longer boot times may only be seen again if the dalvik cache is wiped for some reason. It will also result in negligible performance downgrade.

Themes for android come in .apks too, and if you want to modify any of those, you should always choose a dedoexed custom Rom. However if you don’t care about a color scheme then you should use an odexed file structure.

On a Stock Rom, it’s rather silly to DeOdex. You should better make the switch to a Custom Rom because custom ROMs are already deodexed and they zipalign your apps on boot. Zipaliging is the process of reorganizing the manner in which the .apk is packaged to optimize it for being parsed faster by the Android OS.

How can you check to see if you DeOdexed successfully?

  • Navigate to the directory /system/app with a file explorer & check for the presence of .odex files
  • Navigate to the directory /system/framework & check for the presence of .odex files

If there are no odex files present, then you are deodexed!

2 thoughts on “Odex & Deodex demystified

  1. Pingback: How to Manually Deodex Any Rom on Samsung Galaxy Ace? | Ace Tips

  2. Pingback: How to Deodex Firmware on Samsung Galaxy Ace DDKQ6 « Ace Tips

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s