Performing (de)odex operations

WARNING: This feature is provided as-is and I will not take any responsibility should anything bad happen to your device. These operations cannot be reverted with a full device wipe, only a restore of the original firmware, please make sure to have a backup ready!

NB: It is best to perform this on a PC because those operations are complex and are best achieved on high performance PC, as explained here.

If your device no longer boot after these operations, you will have to restore the system partition by any means necessary. If one or more app(s) keep crashing, you will have to clear their data at best or restore system partition.

 

Every Android device comes either odex'ed or deodex'ed. Odex stands for optimized-DEX and represents the instructions that runs on the device. Every app is delivered with a DEX file code which must be optimized before the code actually runs on the device.

Odex'ing a ROM is the action of optimizing system apps and framework creating the odex (optimized-DEX) files in advance.

  • Odexed ROM are supposed to run faster.
  • Odexed ROM do not support direct theming and customization.
  • A rooted odexed ROM can use Xposed to achieve customization and theming.

Deodex'ing a ROM is the action of removing all optimized-DEX files on the system.

  • Deodexed ROM are supposed to run slower, app code is optimized on first app start.
  • Deodexed ROM can be customized and themed easily.
  • A rooted deodexed ROM can use Xposed to achieve further customization and theming.
See below for a way to backup/restore your files if something goes wrong. Most device comes odexed. WARNING: If you don't know what this is and if it is useful to you, just don't do it. The process can be very long and may even cause issues.

More information is available here.

 

Odexing your ROM

You can odex system apps stored in /system/app, /system/priv-app (Android 4.4+) and /system/framework. Optionally it can remove the original classes.dex from the apps and zip-align the APK for faster loading. On the following device restart, the OS might optimize apps. If it persists upon the following restart, it might be necessary to remove the classes.dex from all apps.
NB: While removing the original classes.dex is safer, reverting it is extremely slow and may cause all system apps signature to be updated, which can create unknown issues.

Deodexing your ROM

You can deodex system apps stored in /system/app, /system/priv-app (Android 4.4+) and /system/framework. Optionally it can rebuild the classes.dex and add it back to the apps.
WARNING: Rebuilding the classes.dex is extremely slow (several hours for the whole ROM!) and may change the signature of affected apps which can create unknown issues.

Preparing for (de)odex operations

Before you start a (de)odex operation, we suggest follow those 2 steps:
  1. Install ADB on your PC (yes a PC is required for recovery)
  2. Enable USB debugging in developper settings
  3. Connect and make sure your device is recognized and you know the basics of using ADB.
  4. Make a copy of those 3 folders: /system/app, /system/priv-app (if it exists) and /system/framework, preferably on your device SD card(s).
This will allow you to recover from potential problems, but not all.

Recovering from issues

If you followed the above steps you should be able to recover following those steps:
  1. Connect device to your PC, and run 'adb shell' in a command window or terminal
  2. Type 'su' to switch to root user, your device might ask you to grant root to adbshell, just confirm.
  3. Move to your backup copy of the 3 folders (for example cd /sdcard/my_backup)
  4. Copy failing apps or entire directories (for example cp -r ./system/app/* /system/app)
  5. Reset permissions on restored directory (for example chmod -R 644 /system/app/* or chmod -R 644 /system/framework/*)
  6. Restore context (if running Lollipop or above) on restored directory (for example restorecon -R /system/app/*)
  7. Run this command 'rm /data/dalvik-cache/*' (WARNING: makes no mistakes with this as it could make things worse)
  8. Reboot your device, either manually or typing 'reboot'.
WARNING: If you don't know what this is or if it is useful to you, just don't do it. Make sure to have a full system backup (original firmware, recovery ZIP) and you know how to restore those.