Android create odex files thru build system 

Joined:
07/27/2010
Posts:
128

May 16, 2011 12:13:34    Last update: May 16, 2011 12:17:17
By Android documentation, odex files are "Optimized DEX" files, which can be created in at least three different ways:
  • The VM does it "just in time". The output goes into a special dalvik-cache directory. This works on the desktop and engineering-only device builds where the permissions on the dalvik-cache directory are not restricted. On production devices, this is not allowed.
  • The system installer does it when an application is first added. It has the privileges required to write to dalvik-cache.
  • The build system does it ahead of time. The relevant jar/apk files are present, but the classes.dex is stripped out. The optimized DEX is stored next to the original zip archive, not in dalvik-cache, and is part of the system image.


The dalvik-cache directory is more accurately $ANDROID_DATA/data/dalvik-cache (/data/dalvik-cache for the emulator).

So how is odex file generated at build time? Prior to Oct. 2010, it was generated by a tool called dexpreopt under the platform/build.git project via dexopt-wrapper, which depends on the emulator. After that, it is generated on the host side with a switch to the make command (dexpreopt was removed from source tree):
$ make WITH_DEXPREOPT=true

Share |
| Comment  | Tags