FORUMS

Galaxy S6 & Edge get €100 Price Cut—New Models Incoming

Samsung has dropped the price of both the Galaxy S6 and S6 Edge by … more

How To Port Fully Featured Sony Xperia Z4 Camera

Xperia Z4’s hardware may not impress, but its software is definitely … more

Experimental TWRP Available For Moto G 2015

XDA Senior Member squid2 has posted experimental builds of TWRP for the Moto G … more

Sunday Debate: How Can We Get a No-Compromise Phone?

Join us in a fun Sunday Debate on Compromises. Come with your opinions and … more

[Complete Guide] What is Odex and Deodex ROM?

7,396 posts
Thanks Meter: 2,923
 
By R_a_z_v_a_n, Recognized Contributor on 21st March 2013, 10:31 AM
Post Reply Subscribe to Thread Email Thread
What is an ODEX file?

In Android file system, applications come in packages with the extension .apk. These application packages, or APKs contain certain .odex files whose supposed function is to save space. These ‘odex’ files are actually collections of parts of an application that are optimized before booting. Doing so speeds up the boot process, as it preloads part of an application. On the other hand, it also makes hacking those applications difficult because a part of the coding has already been extracted to another location before execution.

What is an DEODEX file?

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.

So, Deodexed ROMs (or APKs) have all their application packages put back together in one place, allowing for easy modification such as theming. Since no pieces of code are coming from any external location, custom ROMs or APKs are always deodexed to ensure integrity.

How this works?

For the majority noobs amongst us, Android OS uses a Java-based virtual machine called the Dalvik Virtual Machine. A deodexed or .dex file contains the cache used by this virtual machine (referred to as Dalvik-cache) for a program, and it is stored inside the APK. An .odex file, on the other hand, is an optimized version of this same .dex file that is stored next to the APK as opposed to inside it. Android applies this technique by default to all the system applications.

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.

By deodexing these APKs, a developer actually puts the .odex files back inside their respective APK packages. Since all code is now contained within the APK itself, it becomes possible to modify any application package without conflicting with the operating system’s execution environment.

Advanteges & Disadvantages

The advantage of deodexing is in modification possibilities. This is most widely used in custom ROMs and themes. A developer building a custom ROM would almost always choose to deodex the ROM package first, since that would not only allow him to modify various APKs, but also leave room for post-install theming.

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.

Note:Themes for android come in APKs too, and if you want to modify any of those, you should always choose a dedoexed custom ROM.
Last edited by R_a_z_v_a_n; 25th July 2013 at 11:13 AM.
The Following 163 Users Say Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
 
 
21st March 2013, 10:50 AM |#2  
R_a_z_v_a_n's Avatar
XDA: ASSIST
OP Recognized Contributor
XDA Assist Team
Thanks Meter: 2,923
 
More
[Guide] What is Zipalign and how to make Apps zipaligned
What is Zipalign?

Zipalign is an archive alignment tool introduced first time with 1.6 Android SDK (Software Development Kit). It optimizes the way an Android application package (APK) is packaged. Doing so enables the Android operating system to interact with the application more efficiently, and hence has the potential to make the application and overall the whole system much faster. Execution time is minimized for zipaligned applications, resulting is lesser amount of RAM consumption when running the APK.

How does it exact work?

In an Android operating environment, data files stored in each application package are accessed by multiple processes, for example, the installer will read the data manifest to determine the associated permissions; the system server can read these resources for multiple reasons, like displaying notifications; the Home application, for example, will read resources to get the application’s name and icon. Since Android is based on a a true multi-tasking operating infrastructure, these files are continually and repeatedly accessed. Finally, but not least, the application itself reads the manifest data.

As Android is Linux-based, memory-mapping plays a key role in efficient handling of processes. Essentially, the optimal alignment for the Android OS’ resource-handling code is 4-byte boundaries. What this means is that, if APKs are memory-mapped to 4-byte boundaries, and aligned accordingly, the OS will not need to ‘read through’ the whole application package to get to the desired data manifest. Every system process will know in advance where to look for it’s desired resources, and hence will execute much smoother and faster.

Summing it up, zipaligning an APK results in all uncompressed data within the package to be aligned on 4-byte boundaries, allowing all portions to be accessed directly with the memory-map. RAM consumption is lowered while execution because the querying code doesn’t have to read through the entire application package.

Disavantages 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.


How to make APKs zipaligned?

As mentioned earlier, the zipalign tool became a part of Android SDK from 1.6 onwards. It can be found under the ‘tools’ folder of the SDK. To use it, simply run the command:

Quote:

zipalign [-f] [-v] <alignment> infile.apk outfile.apk

...where infile.apk is the source file, and outfile.apk is the output file.

You can also verify the alignment of an APK file using the following command:

Quote:

zipalign -c -v <alignment> existing.apk

...where existing.apk can be any application package that you need to get verified. Also, the <alignment> tag in both the commands needs to be an integral value (otherwise the command will return invalid). This value, although can be any integer, MUST always be 4, which would provide 32-bit alignment. Any other value and it will effectively do nothing.


Finally, for the flags used in these commands,

Quote:

-f - overwrites existing outfile.zip
-v - will give verbose output
-c - will confirm the alignment of a given file



CAUTION: Zipalign operation must only be performed after you have signed the APK file with your private key. If zipaligned before signing, the signing procedure will disturb the alignment. Same holds true for any other alteration, addition or removal to the APK file. Any change after running zipalign will undo the alignment.

Source: addictivetips
The Following 64 Users Say Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
21st March 2013, 10:53 AM |#3  
R_a_z_v_a_n's Avatar
XDA: ASSIST
OP Recognized Contributor
XDA Assist Team
Thanks Meter: 2,923
 
More

Quote:

Update 08.10.2014

[SCRIPT TO ODEX] Universal Odex Script Version 6.3.1 (11-03-2013)
Quote:

Credits & Thanks for this tool:

MatrixDJ96

Last edited by R_a_z_v_a_n; 9th October 2014 at 09:32 AM. Reason: Tutorials - deodex, re-odex and other stuff
The Following 12 Users Say Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
21st March 2013, 11:01 AM |#4  
GaYoung28's Avatar
Senior Member
Flag D:/Forum/Felix/Location/Indonesia
Thanks Meter: 83
 
Donate to Me
More
Re: [Complete Guide] What is Odex and Deodex ROM?
I think you just must create 1 thread titled "About Android" or someting like that
BTW it is good to know that:thumbup::thumbup:

Sent from my GT-I9070 using xda app-developers app
21st March 2013, 11:15 AM |#5  
R_a_z_v_a_n's Avatar
XDA: ASSIST
OP Recognized Contributor
XDA Assist Team
Thanks Meter: 2,923
 
More
This materials are not created by me, I just searched and read carefully over the WWW in an attempt to bring as much informations to our forum S. Advance.
Only this was my job, along with the desire to know the phone held.

In my opinion, one thread with all the information is difficult to manage, because of that i'm so reluctant in what concerns for easy finding by members.
The Following 5 Users Say Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
21st March 2013, 01:19 PM |#6  
Sami Kabir's Avatar
Senior Member
Flag Manama
Thanks Meter: 1,262
 
Donate to Me
More
Re: [Complete Guide] What is Odex and Deodex ROM?
Make a Guide on how to (Re)Odex a Deodexed ROM if possible...

Sent from my GT-I9070 using xda app-developers app
The Following User Says Thank You to Sami Kabir For This Useful Post: [ View ]
21st March 2013, 01:23 PM |#7  
R_a_z_v_a_n's Avatar
XDA: ASSIST
OP Recognized Contributor
XDA Assist Team
Thanks Meter: 2,923
 
More
Flash stock ROM?
The Following 2 Users Say Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
21st March 2013, 02:45 PM |#8  
Sami Kabir's Avatar
Senior Member
Flag Manama
Thanks Meter: 1,262
 
Donate to Me
More
Quote:
Originally Posted by R_a_z_v_a_n

Flash stock ROM?

Hahahaha.. but I wasn't Joking.. people say that its always better Re-Odex a Deoxed app after editing it
21st March 2013, 03:37 PM |#9  
R_a_z_v_a_n's Avatar
XDA: ASSIST
OP Recognized Contributor
XDA Assist Team
Thanks Meter: 2,923
 
More
Understand now. Let me do some research and read what to do in that sense ...
The Following User Says Thank You to R_a_z_v_a_n For This Useful Post: [ View ]
9th April 2013, 09:13 PM |#10  
sanderg's Avatar
Senior Member
Thanks Meter: 57
 
More
Smile
Quote:
Originally Posted by Sami Kabir

Make a Guide on how to (Re)Odex a Deodexed ROM if possible...

Make it very short then.
Odex Me

(Post useful? Hit the Thanks button etc.)
Last edited by sanderg; 9th April 2013 at 09:13 PM. Reason: typo
The Following 2 Users Say Thank You to sanderg For This Useful Post: [ View ]
11th June 2013, 11:53 AM |#11  
Junior Member
Flag Pune
Thanks Meter: 0
 
More
Odex and Deodex
Hi,

I am a beginner in the android world and i have been trying to understand the android terms in detail. but i am still confused over the ODEX and DEODEX terms. I read you post but it still needs some more explanation of few things mentioned below.

Where is the .ODEX file stored in case of an ODEXED Rom?

Does the Dalvik Cache builds up in case the ROM in Deodexed. If yes then from where it fetches the required information?

Your post says that boot speed is increased in case of both the ODEX & DEODEX ROM after the first Boot. Then what is the exact difference between the two ROMS?

Does Dalvik Cache & DalviK VM independent whether the ROM is ODEX or DEODEX?

Presently my phone is ODEX (Stock ROM), once i DEODEX the ROM can i still install .APK files from Google Play or any other source?

Is tools which makes an APK ODEX or DEODEX part of the android operating system or should we make an APK Odexed or Deodexed using a laptop?

Please help me with the above questions.



Quote:
Originally Posted by R_a_z_v_a_n

What is an ODEX file?

In Android file system, applications come in packages with the extension .apk. These application packages, or APKs contain certain .odex files whose supposed function is to save space. These ‘odex’ files are actually collections of parts of an application that are optimized before booting. Doing so speeds up the boot process, as it preloads part of an application. On the other hand, it also makes hacking those applications difficult because a part of the coding has already been extracted to another location before execution.

What is an DEODEX file?

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.

So, Deodexed ROMs (or APKs) have all their application packages put back together in one place, allowing for easy modification such as theming. Since no pieces of code are coming from any external location, custom ROMs or APKs are always deodexed to ensure integrity.

How this works?

For the majority noobs amongst us, Android OS uses a Java-based virtual machine called the Dalvik Virtual Machine. A deodexed or .dex file contains the cache used by this virtual machine (referred to as Dalvik-cache) for a program, and it is stored inside the APK. An .odex file, on the other hand, is an optimized version of this same .dex file that is stored next to the APK as opposed to inside it. Android applies this technique by default to all the system applications.

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.

By deodexing these APKs, a developer actually puts the .odex files back inside their respective APK packages. Since all code is now contained within the APK itself, it becomes possible to modify any application package without conflicting with the operating system’s execution environment.

Advanteges & Disadvantages

The advantage of deodexing is in modification possibilities. This is most widely used in custom ROMs and themes. A developer building a custom ROM would almost always choose to deodex the ROM package first, since that would not only allow him to modify various APKs, but also leave room for post-install theming.

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.

Note:Themes for android come in APKs too, and if you want to modify any of those, you should always choose a dedoexed custom ROM.

Last edited by fredrickaein; 11th June 2013 at 11:59 AM.

Read More
Post Reply Subscribe to Thread

Tags
deodex, guide, odex, zipalign
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes