Solving 65k method limit error "Unable to execute dex: method ID not in [0, 0xffff]: 65536" in Eclipse.

by Thizzer

Recently I have updated the Android support library for my projects to the latest version and implemented a custom HttpClient due to deprecation on Android’s side. After I made these changes I tried running one of the projects. This resulted in an rerror regarding conversion to the Dalvik format.

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

 

After some research I found out the error was caused due to the fact that the 65k limit of the Dalvik Executable specification for the DEX file was reached. As the Developer Documentation states

 

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.

 

Google has added Multidex support to the latest version of the Android SDK Build Tools. So using the Android Studio you can simply solve this issue by configuring your build.gradle with the following options

 

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

 

But for my projects, Android and others I prefer using Eclipse. In the past I have tried using the Android Studio but I found out that it didn’t work with my project setup and I partially disagree with the idea that every project requires an Android App project at the base of it. 

 

Recently Google announced they will be dropping official support for the Eclipse ADT but will let the Eclipse ADT plugin live on via the Eclipse Foundation’s Andmore project.

 

I discovered that the Andmore project did not yet have support for Multidex. This was a problem because I required it to run my projects. After this discovery I once again started Android Studio and tried to fit my projects inside its philosophy. Once again I came to the conclusion Android Studio is not the tool I prefer. 

 

For the first time ever I decided it was time to contribute to an open source project. This contribution would be adding Multidex support to the Andmore project. So I forked the Github project and started working on adding support for Multidex. 

 

For now I will skip the part what kind of steps I took to add the support. I created a pull request for my modifications and after a few days it was accepted in to the development branch of the Andmore project. 

 

After you have installed the Andmore plugin in Eclipse you can now enable Multidex by following these steps:

 

1. Right click your Android project.

2. Choose Properties.

3. Expand the Android menu.

4. Select General menu.

5. Enable the ‘Enable MultiDex support’ option.

 

This adds two properties to the project.properties file in the root of your Android project. Using the main-dex-list.txt file you can tell which classes to include in the first DEX file that will be loaded when launching your application. This ensures all classes required on launch can be found by the runtime.