javaandroidcompiler-errorsdex

Android gives error "Cannot fit requested classes in a single dex file"


I don't know why but it's impossible to launch my app on my mobile this morning. I get this error message:

Cannot fit requested classes in a single dex file. Try supplying a main-dex list.

# methods: 68061 > 65536 Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. Try supplying a main-dex list.

# methods: 68061 > 65536, sources=[Unknown source file], tool

I'm really new to Android and I don't understand the problem and what I need to do? And why I get this problem now and not before?


Solution

  • In root build.gradle file do something like:

    dependencies {
    
        // ...
    
        implementation 'androidx.multidex:multidex:2.0.1'
    }
    
    android {
        defaultConfig {
    
            // ...
    
            multiDexEnabled true
        }
    }
    

    More details here: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536