【问题标题】:Flutter: Install different versions of dependency for each platform (iOS and Android)Flutter:为每个平台(iOS和Android)安装不同版本的依赖
【发布时间】:2020-03-19 01:02:34
【问题描述】:

我正在尝试在flutter中安装蓝牙的flutter_blue依赖项,并意识到在我的环境中只有0.6.2版适用于android,而^0.6.3+1版适用于ios。

有没有办法声明特定于平台的依赖项或版本?

【问题讨论】:

    标签: flutter flutter-dependencies


    【解决方案1】:

    我遇到了同样的问题,最后做了以下事情:

    1. 为 iOS 创建一个名为 pubspec.ios.yaml 的专用 pubspec。然后,您可以在此处放置任何特定于 iOS 的内容:

      ...
      dependencies:
        flutter:
          sdk: flutter
        flutter_blue: 0.6.3+1
      ...
      
    2. 在我的构建管道中添加一个小脚本:

      # We use a specific pubspec file for iOS
      cp pubspec.ios.yaml pubspec.yaml
      flutter pub get
      

    请注意,重新生成 pubspec.lock 需要“flutter pub get”。

    它有点脏,但我没有想出比这更干净的东西。

    PS:我正在使用 Microsoft App Center for CI/CD,因此在调用 flutter build 之前将上述内容添加到 appcenter-post-clone.sh 脚本中

    # We use a specific pubspec file for iOS
    cp pubspec.ios.yaml pubspec.yaml
    flutter pub get
    
    # The build !
    flutter build ios --release --no-codesign -vvv
    

    【讨论】:

    • 另请注意,iOS 上的 Flutter Blue 版本为 ^0.6.3+1 需要 ObjC 支持。 1. 删除项目中的 ios 文件夹 2. 使用:flutter create -i objc --project-name 重新创建它。来源:github.com/pauldemarco/flutter_blue/issues/…
    • 有人可以对此提供任何想法..会有所帮助..
    猜你喜欢
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2019-11-16
    • 2019-10-19
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    相关资源
    最近更新 更多