Last Updated: February 25, 2016
· fdamilola
Img 2017 02 20 18 28 38

Fixing over 65k methods limitation build error for Android on Android Studio

The android platform is a beautiful platform and with beauty comes a few quirks.

One of them is the over 65k method constraint.

I ran into this snag recently after over 3 years of writing Android applications. I wasn't all that miffed, I was expecting it sooner or later.

This is also the root error that causes the "java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr"
error even after cleaning and re-adding the appcompatv7 library to your project. It can also fix the "java exit with code 2" error while trying to build your app.

Here is a short and direct way to fix this issue and build apps that would work, with the appropriate references at the end of the page.

This article assumes you are familiar with using Android Studio and Gradle.

  • You would need to configure you application for multidex support. View below.

Code :

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'

Note: You can specify the multiDexEnabled setting in the defaultConfig, buildType, or productFlavor sections of your Gradle build file.

  • Run a Gradle sync.

  • In your manifest add the MultiDexApplication class from the multidex support library to the application element.

Code :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

Note : If you have written a custom Application class, just have it extends MultiDexApplication

  • Run your application and all should be well with the world.

You might want to check https://developer.android.com/tools/building/multidex.html for reference and an oversight into the limitations of using MultiDexApplication.

Feel free to drop any ideas or comments.


Say Thanks