Flutter构建因D8而失败:程序类型已存在

时间:2019-04-09 15:48:05

标签: android gradle dart flutter

我正在开发一款Flutter应用程序。

我发现了一个扑扑的样本项目,它很民间。 但是该项目...构建失败,并显示以下日志消息。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* 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 0s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1

该项目并不特殊。 android部分,没有其他修改。 与“新开发项目”完全相同。

我尝试了一些事情:

  1. 迁移到AndroidX

这失败,并弹出错误。我尝试使用“重构>迁移到android x”进行迁移,但显示错误弹出窗口。 对我说的错误弹出窗口至少使用compilesdkversion 28。 但是我已经使用28 ..该怎么办?......

  1. 将gradle版本从3.2.1更改为3.3.2。

但是构建失败并显示了不同的日志

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Program type already present: android.support.v4.app.INotificationSideChannel

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: android.support.v4.app.INotificationSideChannel

我不知道该怎么办...

这让我很累... 我只想编码...

2 个答案:

答案 0 :(得分:0)

我通过以下链接解决了此问题:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

有2个迁移指南。

  1. 推荐

  2. 不推荐

就我而言,“推荐”解决方案不起作用...

但是,“不推荐”解决方案有效...

...

这不容易...

答案 1 :(得分:-1)

我尝试了这两行代码 flutter clean然后 flutter run