How to Enable MultiDex Support in Intellij IDEA

1.2k views Asked by At

I face on compile error "com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536", I search in google the problem is my project reached a limit of method. I following from MultIDex instruction. I added build.gradle, the following is file context of build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 15
buildToolsVersion "21.1.2"

     defaultConfig {
         minSdkVersion 15 //lower than 14 doesn't support multidex
         targetSdkVersion 21

         // Enabling multidex support.
         multiDexEnabled = true
     }

    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

When I build it again, the error still exist, how can I do?

2

There are 2 answers

4
murielK On

You will need also to create a custom application and override the attachBaseContext method as follow:

public class MyApplication extends Application {


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

then add it on your manifest as follow:

 <application
        android:name=".MyApplication"
   .....
 </application>

and voila!

0
EntangledLoops On

I have what other responders have suggested but IntelliJ still doesn't recognize the MultiDex package, even with the library added manually to the project (multidex-1.0.1.aar file, as pulled in by Gradle). The real issue is that IntelliJ doesn't seem to recognize symbols in aar files yet. However, the app still builds via a Gradle task in IntelliJ.