Search code examples
flutterfirebasedartgoogle-cloud-firestorefirebase-authentication

Flutter Error when running: Exception: Gradle task assembleDebug failed with exit code 1


I was trying to make a chat app using flutter and firebase, but then this error happens.

Here are all of the errors

   > There was a failure while executing work items
      > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
         > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
           The number of method references in a .dex file cannot exceed 64K.
           Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 41s
[!] App requires Multidex support
    Multidex support is required for your android app to build since the number of methods has exceeded 64k. See https://docs.flutter.dev/deployment/android#enabling-multidex-support for more information. You may pass the --no-multidex flag to skip Flutter's multidex support to use a manual solution.

    Flutter tool can add multidex support. The following file will be added by flutter:

        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java

cannot prompt without a terminal ui
Exception: Gradle task assembleDebug failed with exit code 1


Solution

  • In most cases, enough will do the first step How to enable multidex for flutter project.

    Enable multidex.

    1. Open [project_folder]/app/build.gradle and add following lines.

       defaultConfig {
           multiDexEnabled true
       }
      

    and

    dependencies {
        ...
    
        implementation 'androidx.multidex:multidex:2.0.1'
    }
    
    1. Enable Jetifier. Open [project_folder]/android/gradle.properties and add following lines.

      android.useAndroidX=true android.enableJetifier=true