6

I am hitting the 65536 limit even though I believe that I do have multidex enabled. I have the following in my build.gradle:

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27

        multiDexEnabled true
    }


    dexOptions {
        preDexLibraries false
        jumboMode true
        keepRuntimeAnnotatedClasses false
        // incremental false
        javaMaxHeapSize "2g" // Use gig increments depending on needs
    }
}

I have my own Application implementation and I have tried extending MultiDexApplication and I have tried calling MultiDex.install(this); in attachBaseContext (not at the same time), but still I keep getting the following error:

D8: Cannot fit requested classes in the main-dex file.
fields: 66685 > 65536
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives

Does this not mean that multidexing is not applied, so somehow multidex is not enabled in my build setup even though I do all I can to enable it, or what can cause this? Any ideas?

Thank you
Søren

Neigaard
  • 3,726
  • 9
  • 49
  • 85
  • 2
    (1/2) Multi-dex is being applied, otherwise the message will be different (will say "in a single dex file" instead of "in the main-dex file". Dex file format has 64k limit for both method and field references. From the error message, it seems that you've hit the fields limit. Why multi-dex doesn't help you? There are rules that force to put specific classes (and its methods or fields references) in a main-dex (a.k.a. classes.dex), and you'll get the mentioned error if you don't enough space for all the "forced" classes. – Alex Lipov Aug 24 '18 at 07:12
  • 2
    (2/2) This generally happen in a large projects that utilize many libraries. The thing is that there is no simple solution (at least that I'm aware of). You can read [here](https://stackoverflow.com/a/32780470/1233652) how I managed to overcome the methods limit in the past, although this solution is not applied anymore (used for older plugin versions). You can try the solutions mentioned [here](http://stackoverflow.com/q/51950860), or try the AGP 3.3 experimental flag mentioned by Jake Wharton [here](https://twitter.com/JakeWharton/status/1032396242062594048). – Alex Lipov Aug 24 '18 at 07:18
  • 1
    see my answer here https://stackoverflow.com/a/57394734/5868421 – Maksim Turaev Aug 07 '19 at 13:25

0 Answers0