Cannot fit requested classes in a single dex file, even for earlier commits which previously compiled fine

Simple add this to your gradle (Module: app) >> multiDexEnabled true

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

then Rebuild Project in Menu click => Build>Rebuild Project.


After looking at your entire build gradle file, your issue definitely stems from your dependencies! Attempt to clean them up and remove as many as you can that you don't use. Chances are you were very close to the limit and any of those dependencies may have been cached using older versions. You can attempt to remove the entire build folder (and clean your gradle cache) but I am fairly certain the issue will not go away.

If all of these dependencies are required unfortunately you will have to go the routes you mentioned, either multi-dex or minifying debug builds. Multi-dex should be ok and shouldn't cause any unforeseen issues while minifying will slow down your builds and potentially cause Android Studio to become unstable (especially instant run/apply changes!)

Good luck, one thing to take from this is to keep your dependencies clean and precise, only add when absolutely needed, and if all else fails, multi-dex is your friend.


None of the answers they gave you were exhaustive. The problem lies in the Multidex. You must add the library in the app gradle:

implementation 'com.android.support:multidex:1.0.3'

After, you should add in the defaultConfig of the app gradle:

multiDexEnabled true