‘D8: Cannot fit requested classes in a single dex file’ error in Flutter/Android Studio


Sometimes you may have end up with this error while starting with a new Flutter project and should tried to google it.

The gradle error caused by the wrong configuration as a result app may not run and end up with the following message.

BUILD FAILED in 1m 0s [!] The shrinker may have failed to optimize the Java bytecode. Exception: Gradle task assembleDebug failed with exit code 1 To disable the shrinker, pass the --no-shrink flag to this command.

Solution

To solve the problem you need to fix the Min SDK version which is wrongly configured. Go to your app level gradle Project ->Android ->app > build.gradle and find the following

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.developerm.kkart"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

and replace the it with the newer  version

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.developerm.kkart"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

and the error will go away, try to rebuild the project.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.