In an Android system, all the code for an app is inside a dex file. Dex is a jar-like archive that stores many Java-compiled bytecode. Because the Android system uses the Dalvik virtual machine, you need to convert the class file that was compiled with Java compiler into a class file that Dalvik can execute. The point here is that Dex, like the jar, is an archive file, which is still a bytecode file for Java code. When the Android system launches an application, one step is to optimize for Dex, a process that has a dedicated tool to handle, called dexopt. The execution of the dexopt is performed when the Dex file is loaded for the first time. This process generates a Odex file, which is optimised Dex. Executing Odex is much more efficient than directly executing the Dex file. But in earlier Android systems, Dexopt's linearalloc had limitations: Android 2.2 and 2.3 buffers only 5mb,android 4.x to 8MB or 16MB. When the number of methods exceeds the buffer size, dexopt crashes, causing the installation to fail.
In addition, because of the Dex file format limitations, the method number in a Dex file is indexed using the primitive type short to index the file, that is, 4 bytes total The maximum number of expressions 65,536 Method,field/class also have this limit. For Dex files, the total number of methods that can be referenced by a single DEX file is limited to 65536 (self-developed and referenced Android) during the consolidation of all the class files required by the project and compression into a Dex file, which is the Dex process packaged by Android. Code for the framework and third-party class libraries).
The solution can be introduced: compile ‘com.android.support:multidex:1.+‘
modify Application extends MultiDexApplication
; Finally, add in Build.gradle defaultconfig:
defaultConfig {multiDexEnabled true}
Android Development Error:the Number of method references in a. dex file cannot exceed 64K.