article

Amelia@Amazon avatar image
Amelia@Amazon posted

Android Multidex library: preventing DX method limit errors easily

Summary

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

https://developer.android.com/tools/building/multidex.html Issue

Receiving one of the following errors mean that the number of methods the application is using must be reduced or the application must use multidexing.

Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

trouble writing output: Too many field references: 131000; max is 65536. You may try using --multi-dex option.

Resolution

Mike Hines has posted a blog post on how to avoid running into this error. That post is available at :

https://developer.amazon.com/public/community/post/Tx291UO6WP91P9Z/Too-Many-Methods-How-to-Avoid-Compile-Errors-on-Submission

This will walk you through how to use the Android Support MultiDex library, and what switches you can pass in your build.gradle file in order to reduce your method count per dex file. In addition to other best practices when dealing with reducing your overall method count in your resulting APK file.

Keywords: MultiDex, Dalvik, Dex, Method Limit

KB_0037

androidlollipop
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Article

Contributors

brizzlebrazzle contributed to this article