Flutter: Build failed with an exception

 ̄綄美尐妖づ 提交于 2019-12-17 14:52:05

问题


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

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/52409592/flutter-build-failed-with-an-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!