65k-Method-limit

Android 65K method limit

To understand Android 65k method limit, let us first understand the basic (a simple way) of how an android apk is built.

Android apk build process

 Android apk build process

  • As shown in the graph, aapt (Android Asset Packaging Tool) collects all the XML files like AndroidManifest file and generate R.java file.
  • R.java file, Java classes + .aidl files are sent to Java Compiler to create .class files (bytecodes).
  • These class files along with class files of external libraries are sent to Dalvik Compiler to create dex files (dalvik executables).
  • These dex files along with other resources like images, audio or video are sent to android package builder to create an apk file, which is then signed and released.

Limitation

The Dalvik VM imposes a limitation on number of methods that can be referenced in a single dex file. The standard limitation is that you can have a maximum of 65,536 method references in a single dex file. This is famously known as Android 65k method limit.

If there are more method references, then you will constantly get the following error:

Android 65k Method Limit

 

This count includes the API method reference too. So, in order to prevent this you may recheck for any APIs that you do not require. But, even if the count does not go low, you may need to create multiple dex files.