Android: my application is too large and gives "Unable to execute dex: method ID not in [0, 0xffff]: 65536"? Android: my application is too large and gives "Unable to execute dex: method ID not in [0, 0xffff]: 65536"? android android

Android: my application is too large and gives "Unable to execute dex: method ID not in [0, 0xffff]: 65536"?


You can also develop one or more of these as a plugin to your main app, in the form of a separate APK available for download. That APK would expose some component that the main app would use -- since I do not know the nature of your integration with these services, I cannot make a more specific recommendation about that. You would use your own signature-level custom <permission> to secure communications between the two apps. And, as a bonus, if using the third-party library adds requirements for additional permissions, you would only need those permissions in the plugin APK, keeping your main APK smaller.


***NEW**** All of the other answers are now outdated. Here's the new fix

Android 5.0 and higher

Multi-dex support is included automatically. From the docs:

Android 5.0 and higher uses a runtime called ART which natively supports loading multiple dex files from application APK files. ART performs pre-compilation at application install time which scans for classes(..N).dex files and compiles them into a single .oat file for execution by the Android device. For more information on the Android 5.0 runtime, see Introducing ART.

Below Android 5.0

Simply add the Android mult-dex support tool to your gradle build:

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'}


The Dalvik VM can have a maximum of 65536 methods per dex file, due to the bytecode instruction set not having a way to refer to method numbers requiring more than 16 bits (as pointed out by @danfuzz in the comments).

While it is possible to fix this using multiple dex files, Facebook found another fix that they could deploy within their app to get around the problem.