o9s
is a microblog
home archives search feed blogroll


Android And The 65K Limit

If you have more than 65,536 methods in your app (including libraries), it will stop compiling. You will get this error.

Unable to execute dex: method ID not in [0, 0xffff]: 65536

I reached this limit fairly quickly when I had Apache Commons as a dependency in one of my apps. It’s a big library.

You can reference a very large number of methods in a DEX file, but you can only invoke the first 65536, because that’s all the room you have in the method invocation instruction.”

-fadden on Stack Overflow

There are a few solutions out there to reduce the number of methods in your app. Reducing the number of methods is not the way to go. You’re only delaying the inevitable. You should fix this issue by enabling multi dex.

dependencies {
  compile 'com.android.support:multidex:{version}'
}
android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

Your custom Application class should inherit from MultiDexApplication instead of Application.

public class MyApplication extends MultiDexApplication
Posted on 2018-03-04   #android     #java  






← Next post    ·    Previous post →