classes dex

Clark writes,

What the heck does odex and deodex actually mean? I see the terms mentioned in almost every custom ROM thread and can't find an answer that I can understand. I'm hoping that Android Central can help out.

Awesome question, Clark. And one I think we can answer in terms that most folks will understand. As you've noted, you see the terms odex and deodexed in many forums posts about custom ROMs or assorted hacks for phones and tablets both. It takes a lot of work for developers to create deodexed ROMs from "stock" ROMs, like the ones offered from both OEMs and Google alike.

To begin, we need to know what an odex file is.  It's a part of an application (the .apk file) that has been prebuilt to make the Dalvik Virtual Machine load it faster using less resources. If you look in the /system/app/ folder on your Android phone or tablet, you'll see that just about every application has both an .apk file and an .odex file. These files work together through the Dalvik VM to make the apps run as they should on our devices. Let's break it all down after the break.

The Dalvik VM

The Dalvik VM is a big part of an Android system. It is the component that allows third party applications written in Java to run on your phone or tablet. The system itself starts the DVM up, and when you press to start an app it goes to work. It takes the data inside the .apk files and using a Just-in-time (JIT) compiler, it builds the information into a program, then runs it. Having portions of the code already optimized and built into a file that the DVM can run makes the process faster, and uses less resources. That's what an odex file is.

Odex files

The odex files you see in your system folder are built by the folks who wrote and built the application itself. Android apps are written in Java, then converted into bytecode. Then, they are converted from the standard Java Virtual Machine compatible .class files into a special type of file that the Dalvik VM can read. These are called .dex files. When these .dex files are placed outside the rest of the code (which is in the .apk file), you are left with a stand alone .odex file. 

There are plenty of good reasons to have stand alone .odex files. They make boot times faster (especially the first boot), by building the Dalvik-cache as the system is booted. They also save some space by pointing to the Android framework whenever possible, and allow the application developer to optimize his or her programs. But having seperate.odex files isn't very hacker friendly.

Deodexing

Deodexing files means taking the stand alone .odex file and the .apk file, and rebuilding them so that all of this pre-built application information is contained inside the .apk file instead of its own file. The pre-built data for the Dalvik VM is now in a classes.dex file inside the .apk file, like in the picture above. That makes the .apk files a bit bigger, and they can't be pre-loaded when the system is fired up. But they can be reverse engineered by hackers and themers.

With all the code and data for the program in one place, you can use tools to "unbuild" the app and edit it however you like. This is how themes and tweaks like battery percentage mods are made for "stock" ROMs. After a developer makes his or her changes, they then rebuild the .apk file and the changes can run. This won't affect any other part of the system because none of the code or data is being shared with other apps. 

Which should you choose? 

That's really up to you, and what your needs will be, but I suggest flashing a deodex version whenever possible. Yes, odex ROMs boot faster, but you really only notice it on the very first boot when all the system apps are pre-cached by the Dalvik VM. You can also save a good bit of space by using odex files, but this space is all in the system partition and won't give you room for more apps if your phone or tablet uses a separate application partition. With todays modern phones and their multi-core processors and huge banks of RAM, you won't even notice any faster application loading times. 

If you want to do things like change the status bar, or theme TouchWiz or Sense, you'll need a deodex ROM. You'll also need a deodex ROM to do some of the really cool deep system tweaks like changing the settings menu or edits to the framework. In short, if you've already unlocked your bootloader and rooted, and you're ready for a custom ROM, choosing a deodexed version is probably the best choice. You'll be amazed at the things these crazy developers can come up with, and you'll surely run into a few you want to try for yourself.

 
There are 18 comments

Awesome question and awesome answer!

bboyairwreck says:

Love this article! Great explanations. I knew sorta what it was but not in detail. This is really interesting, especially as an inspiring developer

Capnwalker says:

I always wondered what that was all about! thanks for making it so clear!

N_Bartolomeo says:

Really useful! Regards

Incubus123 says:

Very informative !

JobiWan144 says:

Thanks, I always wondered about this.

rujelus22 says:

You can mod and reverse engineer odexed apks now. There is no reason to have a deodexed ROM any more. They are slower and since we can edit odexed apk with this http://forum.xda-developers.com/showthread.php?t=1955745 now there in no reason to go deodexed.

joshua.worth says:

Great article Jerry.

bogdaryl says:

Best explanation I've had on this subject. Been trying to find out about this for like a week and now I can say I understand it. THANKS

rawheat#AC says:

I actually enjoyed reading this article. So much, that I created a profile just to write a thank you note to the author (Jerry)!

cyanogen-man says:

Nice article jerry your the best bro :)

21plays says:

Thanks for the 411. Interesting read:-)

ttriplett1 says:

+1 for Jerry!

Evilnut says:

My brain hurts now, I will just go back to using my Android Devices & leave this shit to all the smart people.....

TenshiNo says:

Thanks, Jerry. I've been rooting and rom'ing my Android phones for a couple of years now and had no idea what this meant :) Great to finally know what it means.

CeluGeek says:

You are my hero Jerry! Thanks for the excellent explanation.

owe2003 says:

Thanks for the explanation. Similarly, can you explain what a zip aligned ROM is?

markbc says:

Even today -10 months later, this is a very lucid, and one of the most helpful explanations of the difference between deodex and odex roms; and you threw in a quick clarification on zip alignment as well. . .Very helpful!

thank you Jerry!