简体   繁体   中英

How to Enable MultiDex Support in Intellij IDEA

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?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM