向依赖项添加新包时 Flutter pub 失败

时间:2021-03-09 15:28:58

标签: flutter

当我尝试将 flutter_audio_recorder: ^0.5.5 添加到依赖项时,并且在我推送到“pub get”之后,我遇到如下错误,我该如何解决,有人可以帮助我度过愉快的一天吗??.. ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ....................................

pubspec.yaml

name: lezzet_kitabi
description: A new Flutter application.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  bordered_text: ^1.0.1
  sqflite: ^2.0.0+2
  path_provider: ^2.0.1
  provider: ^5.0.0
  camera: 0.5.8+17
  image_picker: ^0.7.2
  path: ^1.8.0
  vibration: ^1.7.3
  holding_gesture: ^0.0.3
  flutter_audio_recorder: ^0.5.5



dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - images/logoBGopacity.png
    - images/logoBG.png
    - images/cuttedlogo.PNG
    - images/sticker0.png
    - images/sticker1.png
    - images/sticker2.png
    - images/sticker3.png
    - images/sticker4.png
    - images/sticker5.png
    - images/sticker6.png
    - images/sticker7.png
    - images/sticker8.png
    - images/sticker9.png
    - images/sticker10.png
    - images/sticker11.png
    - images/sticker12.png
    - images/sticker13.png
    - images/sticker14.png
    - images/sticker15.png
    - images/sticker16.png
    - images/sticker17.png
    - images/sticker18.png
    - images/sticker19.png
    - images/sticker20.png
    - images/sticker21.png
    - images/sticker22.png
    - images/stickerForRecipeScreen.png

  fonts:
   - family: Marck
     fonts:
       - asset: fonts/MarckScript-Regular.ttf
   - family: Graduate
     fonts:
       - asset: fonts/Graduate-Regular.ttf
   - family: OpenSans
     fonts:
        - asset: fonts/OpenSansCondensed-Light.ttf
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages


错误

Because every version of flutter_audio_recorder depends on file ^5.0.4 and process >=4.0.0 depends on file ^6.0.0, flutter_audio_recorder is incompatible with process >=4.0.0.
And because xdg_directories 0.2.0 depends on process ^4.0.0 and no versions of xdg_directories match >0.2.0 <0.3.0, flutter_audio_recorder is incompatible with xdg_directories ^0.2.0.
And because path_provider_linux 2.0.0 depends on xdg_directories ^0.2.0 and no versions of path_provider_linux match >2.0.0 <3.0.0, flutter_audio_recorder is incompatible with path_provider_linux ^2.0.0.
And because path_provider 2.0.1 depends on path_provider_linux ^2.0.0 and no versions of path_provider match >2.0.1 <3.0.0, flutter_audio_recorder is incompatible with path_provider ^2.0.1.
So, because lezzet_kitabi depends on both path_provider ^2.0.1 and flutter_audio_recorder ^0.5.5, version solving failed.
pub get failed (1; So, because lezzet_kitabi depends on both path_provider ^2.0.1 and flutter_audio_recorder ^0.5.5, version solving failed.)

2 个答案:

答案 0 :(得分:1)

您的软件包 flutter_audio_recorder 依赖于 file 软件包版本 5.0.4,但同时您的 process 软件包依赖于 file 版本 6.0.0。现在由于两者同时使用,一个包需要 5.0.4 版本,一个包需要 file 包的 6.0.0 版本。因此,由于这种“冲突”,您会收到错误消息。您可以阅读文档,了解其工作所需的其他软件包的版本,并降级软件包的版本之一,错误将得到解决。

既然写到 flutter_audio_recorder 的“每个版本”都依赖于 file 5.0.4 版。我认为您应该添加另一个名为 process 的包并添加它的降级版本,可能是 3.0.0 或 3 范围内的某个版本,它可能会解决您的问题。

这种类似的“冲突”也发生在其他软件包之间。您可以通过更改它们的版本来解决此问题。

几天前我也遇到了类似的问题,这对我有用。

答案 1 :(得分:0)

https://marketplace.visualstudio.com/items?itemName=jeroen-meijer.pubspec-assist

你可以安装上面的vs code扩展,并通过扩展重写依赖。

错误的原因是你的所有依赖项都必须依赖于其他包的类似版本,如果它们有共同的包。