Understanding DEX, VDEX, ODEX and ARouter Optimization in Android Development
The article explains Android’s DEX compilation flow, the transformation of DEX into VDEX and ODEX during ART pre‑optimization, why ODEX lacks the original classes.dex causing ARouter routing failures, and how disabling dex stripping in the build restores the missing classes for stable navigation.
Author: vivo Internet Client Team - Xu Jie. This article addresses common questions about DEX files, their optimization, and the impact on Android projects.
1.1 APK Compilation and Packaging Process
1) Use aapt to package resources, generating R.java , resources.arsc and the res directory.
2) Process aidl files to generate Java interface files (if any).
3) Compile R.java and other Java files with the Java compiler to produce .class files.
4) Convert .class files (including third‑party SDK classes) into classes.dex using the dex tool.
5) Use apkbuilder to combine the compiled resources and classes.dex into an APK.
6) Sign the APK with jarsigner for debug or release builds.
In practice, steps 5 and 6 are often automated by a Jenkins pipeline to produce release packages directly.
1.2 Common Scenarios for DEX Files
DEX files are used for APK size reduction, hot‑fixes, plug‑in architectures, app protection, Android reverse engineering, and the 64K method limit. When the method count exceeds 65,536, developers enable multidex with multiDexEnabled true in Gradle.
2. DEX to VDEX and ODEX
2.1 ART Pre‑Optimization
ART (Android Runtime) replaced Dalvik (DVM) as the default VM starting from Android 5.0. DVM executes DEX bytecode, while ART executes optimized native code (OAT). DVM uses JIT (Just‑In‑Time) compilation; ART uses AOT (Ahead‑Of‑Time) compilation, converting DEX to OAT during installation, which reduces runtime memory usage and improves performance.
2.2 ART Execution Modes
From Android 7.0 onward, ART combines AOT, JIT, and profile‑guided compilation. Example workflow on Pixel devices:
Initial install: no AOT; first few runs use interpretation and JIT for hot methods.
When the device is idle and charging, a compilation daemon runs AOT on frequently used code based on generated profile files.
Subsequent launches use profile‑guided code, avoiding redundant JIT compilation.
ART includes the dex2oat tool, which takes an APK and produces one or more compiled files. On Android O, the generated files are:
vdex : contains uncompressed DEX code plus metadata to speed up verification.
odex : contains AOT‑compiled method code.
art (optional) : internal ART representation of selected strings and classes for faster startup.
2.3 Role of VDEX and ODEX
Extracting an APK (e.g., a system app) may show a directory structure without any DEX files. VDEX and ODEX files contain the compiled code and usually also include classes.dex . However, because they are machine code, they cannot be directly inspected as plain DEX.
Tools like 010Editor confirm that ODEX does not contain a DEX file, and attempts to extract DEX from VDEX also fail, indicating that the assumption "odex (or vdex) contains classes.dex" is incorrect.
3. What is ARouter?
ARouter is Alibaba's routing component for page navigation in Android apps. It supports pluginization and can generate mapping documentation. When DEX files move or are dynamically delivered, ARouter may fail to locate routes, leading to ClassNotFoundException .
4. Pitfalls and Solutions
4.1 Symptom
Because ODEX does not contain DEX, ARouter cannot find the required class files, resulting in ClassNotFoundException during navigation.
4.2 Solution
Configure ART to prevent ODEX optimization by setting LOCAL_DEX_PREOPT := nostripping in Android.mk . This keeps the original DEX files in the APK while still generating ODEX for performance.
After rebuilding the APK with this setting, the classes.dex file is retained, ARouter can locate its route definitions, and the navigation error disappears.
5. Summary
ODex optimization performed by the system can lead to unexpected issues, especially when third‑party frameworks are involved. While ODEX usually does not interfere with class paths, misconfigurations can cause failures. Properly configuring ART (e.g., disabling dex stripping) helps avoid these pitfalls and ensures stable routing with components like ARouter.
vivo Internet Technology
Sharing practical vivo Internet technology insights and salon events, plus the latest industry news and hot conferences.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.