Search code examples
iosflutteraws-amplify

How to correctly implement Amplify to Flutter


for the last few days, I was trying to figure out how to fix the issues I was having with Amplify for Flutter: error: compiling for iOS 9.0, but module 'Starscream' has a minimum deployment target of iOS 11.0 and Target of URI doesn't exist: 'package:amplify_core/amplify_core.dart'

Things I tried:

  1. Following the tutorial of the doc https://docs.amplify.aws/start/getting-started/setup/q/integration/flutter. That resulted in: 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.swiftmodule and Command CompileSwift failed with a nonzero exit code note: Using new build system note: Building targets in parallel note: Planning build note: Contructing build description. I uncommented the line platform :ios, '9.0' on Podfile and changed it to platform :ios, '11.0', while also changing the development target to 11 on the projects xcworkspace. The same error happened.

  2. Following the tutorial of the doc https://aws.amazon.com/getting-started/hands-on/build-flutter-app-amplify/. That resulted in:Target of URI doesn't exist: 'package:amplify_core/amplify_core.dart' when I tried to import the core. Like that, I couldn't use the Amplify() class.

  3. Restarting the computer.

  4. Deleting the Amplify folder.

  5. Running amplify uninstall, and trying from the start again.

  6. Searching other posts on this and other websites.

  7. Running amplify clean.

Things to note:

  1. The Amplify installation, init, and configure steps returned no errors.
  2. If I delete the Amplify dependencies amplify_flutter: '<1.0.0' amplify_auth_cognito: '<1.0.0' amplify_analytics_pinpoint: '<1.0.0' the app runs on the simulator just fine. As soon as I put them back the errors return.

Solution

  • You want to change import 'package:amplify_core/amplify_core.dart' to import 'package:amplify_flutter/amplify.dart'; then when you add your plugins you'll wanna do it like this Amplify.addPlugins([authPlugin, storage]);

    I also ran flutter upgrade before I did this as well just make sure you save all your changes. You can find more information in there example flutter app

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