【问题标题】:Firestore dependency error flutterFirestore依赖错误颤动
【发布时间】:2019-01-31 14:58:47
【问题描述】:

我有这个运行良好的应用程序。现在我需要添加 Firestore 功能,但它无法构建。 控制台错误:

Launching lib\main.dart on Phone in debug mode...
Configuration 'compile' in project ':app' is deprecated. Use 
'implementation' instead.
registerResGeneratingTask is deprecated, use 
registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use 
registerGeneratedFolders(FileCollection)

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

BUILD FAILED in 2m 3s
Gradle build failed: 1
Exited (sigterm)

app/build.gradle

中添加行 implementation 'com.google.firebase:firebase-firestore:17.1.0' 后出现错误
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.1'
compile 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-firestore:17.1.0'  //if I comment out this line the app compiles and builds normally. 
//Also I can use FirebaseAuth in the app so I don't think I have wrongly configured Firebase
}

Gradlew 日志

      Task :app:compileDebugJavaWithJavac
Putting task artifact state for task ':app:compileDebugJavaWithJavac' into context took 0.0 secs.
file or directory 'C:\Users\rober\OneDrive\Documents\VS\appname\android\app\src\debug\java', not found
Skipping task ':app:compileDebugJavaWithJavac' as it is up-to-date (took 0.117 secs).

:app:compileDebugJavaWithJavac (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 0.136 secs.
:app:transformClassesWithDexBuilderForDebug (Thread[Task worker for ':' Thread 3,5,main]) started.

> Task :app:transformClassesWithDexBuilderForDebug
Putting task artifact state for task ':app:transformClassesWithDexBuilderForDebug' into context took 0.0 secs.
Skipping task ':app:transformClassesWithDexBuilderForDebug' as it is up-to-date (took 0.162 secs).

:app:transformClassesWithDexBuilderForDebug (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 0.162 secs.
:app:transformDexArchiveWithExternalLibsDexMergerForDebug (Thread[Daemon worker Thread 7,5,main]) started.

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug
Putting task artifact state for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' into context took 0.0 secs.
Executing task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' (up-to-date check took 0.077 secs) due to:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

:app:transformDexArchiveWithExternalLibsDexMergerForDebug (Thread[Daemon worker Thread 7,5,main]) completed. Took 1.029 secs.

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 --debug option to get more log output.

我什至尝试在 Android Studio 中运行它,但仍然一无所获。添加其他依赖项,例如 cloud storagecloud messaging,应用程序将正常构建。但是添加firestore这一行后,出现错误

【问题讨论】:

  • 我添加了flutter run -v日志
  • 我该怎么做,--info 部分
  • 您可以只运行导致故障隔离的部分:projectDir/android/gradlew transformDexArchiveWithExternalLibsDexMergerForDebug --infoflutter run 未使用的附加 --info 将显示实际的 DexMerger 错误。
  • 当我运行它时,它会打开 cmd 并在完成时开始运行。 cmd 直接退出,没有时间阅读结果。所以我直接在cmd 中运行命令,结果我已经发布但不确定它是否完全是错误
  • 没有。发现我做错了什么。检查日志更新

标签: android gradle android-gradle-plugin flutter


【解决方案1】:

终于在 Stackoverflow 上的另一篇文章中找到了答案 这几行代码应该添加到 build.gradle 文件中(模块:app)。

android {
    defaultConfig {
       multiDexEnabled true
    }
}

【讨论】:

  • 这是我首先怀疑的,但你的帖子更新在这方面对我没有帮助。
  • 如果您将firestore版本更改为16.0.0,它也可以在不添加multiDexEnabled = true的情况下工作
猜你喜欢
  • 2021-01-19
  • 1970-01-01
  • 2019-07-02
  • 2021-09-16
  • 1970-01-01
  • 2014-12-13
  • 2018-04-10
  • 2015-02-10
  • 2020-01-28
相关资源
最近更新 更多