Search code examples
androidandroid-multidex

Too many method references: 107085; max is 65536 after extending MultiDexApplication


[2015-07-16 17:32:14 - Loneous] Dx 
trouble writing output: Too many method references: 107085; max is 65536.
You may try using --multi-dex option.

I have this error and I have extended my Application class with MultiDexApplication, but still I am getting this error.

@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

Also added the attachBaseContext method in my application.

Kindly guide me how to avoid this compilation error and run my app successfully.


Solution

    1. Edit your manifest.xml and add a reference to your MultidexApplication class

      <application android:name="your.package.MyApplicationWhichExtendsMultidex">
      
    2. Go to your grandle build file and add

      multiDexEnabled true
      

      and a dependency to the multidex support

      compile 'com.android.support:multidex:1.0.0'
      

    I don't know how Eclipse handle Android projects, but if it doesn't use Gradle then you need to pass --multi-dex option (as the error said) during the build. If you are still using Ant, move to Gradle or Maven.

    I've found for you the official documentation about how to fix this problem