Android Development Error:the Number of method references in a. dex file cannot exceed 64K.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.