如何向我的应用添加flutter_local_notifications?

时间:2019-04-28 18:13:38

标签: dart flutter flutter-dependencies

我想使用flutter_local_notifications在我的应用中添加通知,但是一旦将插件添加到.yaml中,我的应用就不会再次运行。 以下是错误

```D8: Program type already present: android.support.v4.app.INotificationSideChannel

失败:构建失败,并出现异常。

  • 出了什么问题: 任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。

      

    com.android.builder.dexing.DexArchiveMergerException:合并dex归档文件时出错:/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/2.jar,/ Users / macbook / AndroidStudioProjects /restaurant/build/app/intermediates/transforms/dexBuilder/debug/3.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/6.jar,/Users/macbook/AndroidStudioProjects /restaurant/build/app/intermediates/transforms/dexBuilder/debug/7.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/8.jar,/Users/macbook/AndroidStudioProjects /restaurant/build/app/intermediates/transforms/dexBuilder/debug/9.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/10.jar,/Users/macbook/AndroidStudioProjects /restaurant/build/app/intermediates/transforms/dexBuilder/debug/11.jar,/Users/macbook/AndroidStudioProjects/restaurant/bui ld / app / intermediates / transforms / dexBuilder / debug / 12.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 13.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 14.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 15.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 16.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 17.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 18.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 19.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 20.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transfo rms / dexBuilder / debug / 21.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 22.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 23.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 24.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 25.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 26.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 27.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 28.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 29.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 30.jar, /Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/31.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/32.jar, /Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/33.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/34.jar, /Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/35.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/36.jar, /Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/37.jar,/Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/38.jar, /Users/macbook/AndroidStudioProjects/restaurant/build/app/intermediates/transforms/dexBuilder/debug/39.jar,/Users/macbook/AndroidStudi oProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 40.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 41.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 42.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 43.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 44.jar,/ Users / macbook / AndroidStudioProjects / restaurant / build / app / intermediates / transforms / dexBuilder / debug / 45.jar   在https://developer.android.com/studio/build/dependencies#duplicate_classes了解如何解决该问题。   程序类型已经存在:android.support.v4.app.INotificationSideChannel

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。

  • https://help.gradle.org

  • 获得更多帮助

在29秒内失败


Gradle失败可能是由于此Flutter应用程序中的AndroidX不兼容所致。 有关此问题及其解决方法的更多信息,请参见...。


完成错误:Gradle任务assembleDebug失败,退出代码为1```

谢谢。

1 个答案:

答案 0 :(得分:0)

首先,您需要将所有软件包升级到与AndroidX兼容的版本。您可以从dart packages page上每个包的ChangeLog.md知道这一点。接下来,您需要在AndroidStudio中打开flutter的android项目,然后选择Refactor-> Migrate to AndroidX。稍等片刻,直到android studio重构您的项目。并从android studio运行重建项目。这样就可以了!