Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Build failed with an exception

I am trying to use FirebaseAuth in a flutter application. I can use Firestore service but when i include firebase_auth depedency in pubspec.yaml file i got the following exception.

FAILURE: Build failed with an exception.

* What went wrong:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get
more log output.

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

here is my pubspec.yaml file


dependencies:
  flutter:
    sdk: flutter
  intl: ^0.15.6
  #firebase_core: ^0.2.2
  google_sign_in:
    git:
      url: http://github.com/jahirhstu/flutter_plugins.git
      path: packages/google_sign_in
  #firebase_analytics: 
  #  git:
  #    url: http://github.com/jahirhstu/flutter_plugins.git
  #    path: packages/firebase_analytics
  firebase_auth:
    git:
      url: http://github.com/jahirhstu/flutter_plugins.git
      path: packages/firebase_auth
  cloud_firestore:
    git:
      url: http://github.com/jahirhstu/flutter_plugins.git
      path: packages/cloud_firestore
  cupertino_icons: ^0.1.0
  shrine_images: 1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
like image 274
Jahirul Islam Avatar asked Sep 19 '18 15:09

Jahirul Islam


People also ask

What is flutter clean command?

Method 1: Run Command Flutter Clean Open your flutter project folder in Command Prompt or Terminal. Then type flutter clean command and press enter. After executing flutter clean command we would see that it will delete the dart-tools folder, android folder and iOS folder in our application with debug file.


2 Answers

Well, I was trying to solve it and what I did was:

*1.-Reinstall Flutter

2.-Reinstall Dart SDK

3.-Download Gradle 5.1.1

4.-Create a new Application with Firebase and include dependencies

5.-Compile again*

And all of these didnt work.

Then I did:

6.-Copy next lines at the end of gradle.properties

android.useAndroidX=true
android.enableJetifier=true

7.-Changes on file app\build.gradle

android {
    compileSdkVersion 28

...

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

}

8.-Optionally you can add code inside subproject{} in file android\build.gradle

subprojects {
    ...
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
        }
    }
}

9.-Go to terminal and launch command

flutter clean

10.-Run your app.

Hope will be helpful

like image 197
Yury Euceda Avatar answered Oct 18 '22 11:10

Yury Euceda


In your Project folder > android > app > build.gradle: add the following Line in defaultConfig { .... multiDexEnabled true }

enter image description here

like image 32
anmol.majhail Avatar answered Oct 18 '22 09:10

anmol.majhail