What process happens when there is a system optimization?


Question

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.


Answer

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




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes