title | description |
---|---|
Swift Package Manager for app developers |
How to use Swift Package Manager for native iOS or macOS dependencies |
:::warning Flutter is migrating to Swift Package Manager to manage iOS and macOS native dependencies. Flutter's support of Swift Package Manager is under development. If you find a bug in Flutter's Swift Package Manager support, open an issue. Swift Package Manager support is off by default. Flutter continues to support CocoaPods. :::
Flutter's Swift Package Manager integration has several benefits:
- Provides access to the Swift package ecosystem. Flutter plugins can use the growing ecosystem of Swift packages.
- Simplifies Flutter installation. Xcode includes Swift Package Manager. You don't need to install Ruby and CocoaPods if your project uses Swift Package Manager.
{% include docs/swift-package-manager/how-to-enable-disable.md %}
{% tabs %} {% tab "iOS project" %}
{% include docs/swift-package-manager/migrate-ios-project.md %}
{% endtab %} {% tab "macOS project" %}
{% include docs/swift-package-manager/migrate-macos-project.md %}
{% endtab %} {% endtabs %}
{% tabs %} {% tab "iOS project" %}
{% include docs/swift-package-manager/migrate-ios-project-manually.md %}
{% endtab %} {% tab "macOS project" %}
{% include docs/swift-package-manager/migrate-macos-project-manually.md %}
{% endtab %} {% endtabs %}
Flutter's Swift Package Manager support doesn't work with add-to-app scenarios.
To keep current on status updates, consult flutter#146957.
Your Flutter Xcode project can have custom Xcode targets to build additional products, like frameworks or unit tests. You can add Swift Package Manager integration to these custom Xcode targets.
Follow the steps in How to add Swift Package Manager integration to a project manually.
In Step 1, list item 6 use your custom target instead
of the Flutter
target.
In Step 2, list item 6 use your custom target instead
of the Flutter
target.
To add Swift Package Manager integration, the Flutter CLI migrates your project. This migration updates your Xcode project to add Flutter plugin dependencies.
To undo this migration:
-
Clean your project:
flutter clean
-
Open your app (
ios/Runner.xcworkspace
ormacos/Runner.xcworkspace
) in Xcode. -
Navigate to Package Dependencies for the project.
-
Click the
FlutterGeneratedPluginSwiftPackage
package, then click remove.{% render docs/captioned-image.liquid, image:"development/packages-and-plugins/swift-package-manager/remove-generated-package.png", caption:"The
FlutterGeneratedPluginSwiftPackage
to remove" %} -
Navigate to Frameworks, Libraries, and Embedded Content for the
Runner
target. -
Click
FlutterGeneratedPluginSwiftPackage
, then click the remove.{% render docs/captioned-image.liquid, image:"development/packages-and-plugins/swift-package-manager/remove-generated-framework.png", caption:"The
FlutterGeneratedPluginSwiftPackage
to remove" %} -
Go to Product > Scheme > Edit Scheme.
-
Expand the Build section in the left side bar.
-
Click Pre-actions.
-
Expand Run Prepare Flutter Framework Script.
-
Click delete.
{% render docs/captioned-image.liquid, image:"development/packages-and-plugins/swift-package-manager/remove-flutter-pre-action.png", caption:"The build pre-action to remove" %}
If a Swift Package Flutter Manager plugin requires a higher OS version than the project, you might get an error like this:
Target Integrity (Xcode): The package product 'plugin_name_ios' requires minimum platform version 14.0 for the iOS platform, but this target supports 12.0
To use the plugin:
-
Open your app (
ios/Runner.xcworkspace
ormacos/Runner.xcworkspace
) in Xcode. -
Increase your app's target Minimum Deployments.
{% render docs/captioned-image.liquid, image:"development/packages-and-plugins/swift-package-manager/minimum-deployments.png", caption:"The target's Minimum Deployments setting" %}
-
If you updated your iOS app's Minimum Deployments, regenerate the iOS project's configuration files:
flutter build ios --config-only
-
If you updated your macOS app's Minimum Deployments, regenerate the macOS project's configuration files:
flutter build macos --config-only