7/05/2016

DEX 64K Reference Limit

When the source of your Android app grew too much or you use too much 3rd party libraries, you might meet DEX 64K Reference Limit. As you are building and install your APK, the error happens like below:

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

What is DEX 64K Reference Limit 

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(64K)—including Android framework methods, library methods, and methods in your own code.

How to resolve or avoid it


1. Use Proguard to shrinks, optimizes and obfuscates your code by removing unused code and renaming classes, fields and methods with semantically obscure names. I won't tell too in this article.

2. Enable multidex.Configure your app build process to generate more than one DEX file

3. Use Jar Jar Links utility repackage Java libraries, remove some unnecessary packages from 3rd parties libraries.


Reference:
https://developer.android.com/studio/build/multidex.html#about

No comments:

Post a Comment