Table of contents

Android Cannot fit requested classes in a single dex file (# methods: 72777 > 65536)

Android Jun 30, 2020 Viewed 255 Comments 0

Issue

When integrating react-native-navigation into React Native app, an error occurs when building on Android Studio.

Error: null, Cannot fit requested classes in a single dex file (# methods: 72777 > 65536)

Solution

The main reason is that the project is a bit large, with more than 65k methods. A dex can't be installed anymore, and multiple dexes are needed, because the total number of methods defined by the Android system is a short int, and the maximum value of short int is 65536.

Remove unnecessary dependencies, and ensure that the dependencies of the build.gradle file are as clean as possible. If all dependencies are required, you can try adding a line of multiDexEnabled true to the android/app/build.gradle file.

android {
    ...
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
+       multiDexEnabled true    // Add this line
    }
}
dependencies {
    ...
}

Build again.

Updated Jun 30, 2020