【问题标题】:How to correctly implement Amplify to Flutter如何正确实现 Amplify to Flutter
【发布时间】:2021-02-03 01:00:50
【问题描述】:

在过去的几天里,我试图弄清楚如何解决我在使用 Amplify for Flutter 时遇到的问题:error: compiling for iOS 9.0, but module 'Starscream' has a minimum deployment target of iOS 11.0Target of URI doesn't exist: 'package:amplify_core/amplify_core.dart'

我尝试过的事情:

  1. 遵循文档https://docs.amplify.aws/start/getting-started/setup/q/integration/flutter 的教程。结果是:project directory/ios/Pods/AppSyncRealTimeClient/AppSyncRealTimeClient/Connection/AppSyncConnection/AppSyncSubscriptionConnection+ErrorHandler.swift:9:8: error: compiling for iOS 9.0, but module 'Starscream' has a minimum deployment target of iOS 11.0: project directory/build/ios/Debug-iphonesimulator/Starscream/Starscream.framework/Modules/Starscream.swiftmodule/x86_64-apple-ios-simulator.swiftmoduleCommand CompileSwift failed with a nonzero exit code note: Using new build system note: Building targets in parallel note: Planning build note: Contructing build description。 我在 Podfile 上取消注释 platform :ios, '9.0' 并将其更改为 platform :ios, '11.0',同时还将项目 xcworkspace 上的开发目标更改为 11。发生了同样的错误。

  2. 遵循文档https://aws.amazon.com/getting-started/hands-on/build-flutter-app-amplify/ 的教程。当我尝试导入核心时,这导致:Target of URI doesn't exist: 'package:amplify_core/amplify_core.dart'。像那样,我不能使用 Amplify() 类。

  3. 重新启动计算机。

  4. 删除 Amplify 文件夹。

  5. 运行amplify uninstall,并从头开始尝试。

  6. 在此网站和其他网站上搜索其他帖子。

  7. 正在运行amplify clean

注意事项:

  1. Amplify 安装、初始化和配置步骤未返回任何错误。
  2. 如果我删除 Amplify 依赖项amplify_flutter: '<1.0.0' amplify_auth_cognito: '<1.0.0' amplify_analytics_pinpoint: '<1.0.0' 应用程序在模拟器上运行就好了。一旦我把它们放回去,错误就会返回。

【问题讨论】:

  • 对于第一个错误,为我解决的问题是进入 ios 目录并在 Podfile 中将“platform ios:”更改为更高的部署,例如 12。至于第二个问题,我现在也遇到了,不知道怎么解决。

标签: ios flutter aws-amplify


【解决方案1】:

您想将 import 'package:amplify_core/amplify_core.dart' 更改为 import 'package:amplify_flutter/amplify.dart'; 然后当您添加插件时,您会想要这样做 Amplify.addPlugins([authPlugin, storage]);

在执行此操作之前,我还运行了flutter upgrade,只要确保您保存所有更改即可。您可以在示例颤振应用中找到更多信息

https://github.com/aws-amplify/amplify-flutter/blob/master/example/lib/main.dart

【讨论】:

  • 好吧,我现在确实很困惑,因为在进行了您建议的更改后,同样的compiling for iOS 9.0, but module 'Starscream' 错误发生了,但是有了@seanbrhn3 的评论,我意识到如果我将平台更改为 iOS 12,返回错误has a minimum deployment target of iOS 12.0。 iOS 13 也发生了同样的事情,所以我尝试了 iOS 9,它成功了。不知道为什么,但我现在会接受你的回答,如果有任何变化,我会告诉你们。非常感谢,真的很有帮助。
  • 请注意,Amplify Flutter 要求最低 iOS 目标为 11.0。参考:docs.amplify.aws/lib/auth/getting-started/q/platform/…
【解决方案2】:

如果你正在关注本教程https://docs.amplify.aws/start/getting-started/setup/q/integration/flutter

然后在依赖的步骤中有一个更正: https://docs.amplify.aws/start/getting-started/setup/q/integration/flutter#add-amplify-to-your-application

应该是这样的:

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

dev_dependencies:

  amplify_flutter: <1.0.0
  amplify_datastore: <1.0.0
  amplify_api: <1.0.0
  amplify_auth_cognito: <1.0.0
  flutter_test:
    sdk: flutter
  

然后运行:

颤抖干净

颤振酒吧获取

【讨论】:

  • 它不应该在 dev_dependencies 下
猜你喜欢
  • 2019-06-15
  • 1970-01-01
  • 2020-06-27
  • 2020-01-08
  • 2018-08-04
  • 2020-08-10
  • 1970-01-01
  • 2018-08-13
  • 2015-02-27
相关资源
最近更新 更多