3

My question is the following: Not long ago I was moving apk, data and .dex files to the directories / data, and they did not show the applications I had manually installed, if not until I rebooted on the device and a message appeared saying "optimize the system" from the moment I was curious about this.

My purpose is to learn what happens in this process and to know how to be able to repeat it manually.

If you know anything about this, I'll be happy to hear your comments and answers.

2
  • 1
    To repeat this process, install the APK file as you normally will. Odex-ing is part of the installation process.
    – iBug
    Commented May 30, 2017 at 5:51
  • It can be misleading that files in /data/dalvik-cache/ have the extension of .dex, because their actual format is odex and is different from what you extract from APK.
    – iBug
    Commented May 30, 2017 at 5:55

1 Answer 1

7

What is Android doing when it says “optimizing apps/system”?

Basically the android system will be creating an optimised version of each application. This process makes each app start as fast as possible with the new Android version.

While it says ‘optimising,’ operating system generates ‘odex’ files for your apps from scratch. As a simple explanation, odex files can help the system boot faster and reduces the time needed for launching applications.

Apk files and odex files

The longer story is that when an APK file is added to your Android system, it’s not actually stored that way. It’s converted to something called an “odex” file.

The Android OS does not store apps as is after installation (i.e., one single APK file). An optimized version of the app is stored in the Dalvik cache — called the odex file.”

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 (Optimized Dalvik EXecutable) 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.

Deodex

Deodexing is basically repackaging of these APKs in a certain way, such that they are reassembled into classes.dex files (Dalvik EXecutable).

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.

In summary, 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.

There are several explanations on how this works:

In Android, 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.

Android OS uses a Java-based virtual machine for running applications, 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. 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. 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.

How to do the process manually;

If you want to manually optimise your apks, there are some options:

Acknowledgements

6
  • Thanks for the info, but I have another question, I already copied the dex in the dalvik-cache directory, however the app icon is not displayed in the android launcher.
    – Abraham.P
    Commented Apr 29, 2017 at 18:25
  • Because the .dex will not be "built" into te dalvik virtual machine as explained above, and this process happens during booting hence you have to reboot after movibg your dex file so that it will be optimised first in cache, and associated parts moved to respective locations. Commented Apr 29, 2017 at 18:48
  • But there is no way to activate this process at any time without having to restart the device. Thank you
    – Abraham.P
    Commented Apr 29, 2017 at 18:52
  • Nevertheless, did the explanation help you understand what happens when android says "system is optimising"?. From the look of things, it seems that was the main question , I aplologise if I misquoted you Commented Apr 29, 2017 at 18:59
  • 1
    The link you provided for Lucky Patcher is not the official site. It have the potential of containing malware. This link (above) is correct.
    – iBug
    Commented May 30, 2017 at 5:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .