Dexing is the process of converting standard Java JVM byte code (in the form of a .jar archive file created by the compiler) into Android's native format, Dalvik or ART.

This is done by a tool called dex or its more modern replacement d8, which is part of the standard Android build tools. EBuild will take care of running this tool for you as part of the regular build process, but it can still be important to know what is going on, for more complex use cases.

By default, EBuild will use the newer d8 tool, when available, falling back to dex on older versions of the Android SDK that do not support d8.




The dexing process can take some time, and pre-dexing eliminates overhead by dexing referenced libraries ahead of the compile phase, and caching the pre-dexed copies so that they do not have to be processed again for each compile, when they likely have not changed.

Pre-Dexing can be enabled by setting the AndroidDexMode setting to PreDex (the default).

Incremental Dexing



Android has a limit on the size for each individual .dex file generated by the dexing process. To allow for larger projects, a technology called "multi-dex" is used, which will spread out the compiled types across multiple .dex files. When using d8, multi-dexing will happen by default, but for the legacy dex tool, multi-dexing can be enabled or disabled manually with a project setting called AndroidPackMultidex, which defaults to False.

For older Android platforms (lower than SDK version 21) some additional concerns might arise when multi-dexing. Devices on 21 or later use the newer Android Runtime (ART) instead of Dalvik, which according to the docs compiles all apps into a single executable using the on-device dex2oat tool. This utility accepts .dex files as input and generates a compiled app executable for the target device.

On ART it doesn't matter which .dex file individual classes end up in, since all .dex files are compiled into a single .oat file at install time, and ART executes this .oat file when launching the app.

For multidexed apps targeting a Deployment SDK of 20 or lower, you will need to follow the Android docs on supporting MultiDex and add a text file with the classname of your custom Application class to the project, as described here. You need to set the AndroidMainDexListFile project setting to point to this file.

Note: EBuild's AndroidMainDexListFile is the exact equivalent of Gradle's multiDexKeepFile. They both pass the same parameter to the same Android build tool and nothing more.