Skip to content

Latest commit

 

History

History
177 lines (118 loc) · 5.89 KB

File metadata and controls

177 lines (118 loc) · 5.89 KB
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:

  1. Provides access to the Swift package ecosystem. Flutter plugins can use the growing ecosystem of Swift packages.
  2. 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 %}

How to add Swift Package Manager integration

Add to a Flutter app

{% 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 %}

Add to a Flutter app manually

{% 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 %}

Add to an existing app (add-to-app)

Flutter's Swift Package Manager support doesn't work with add-to-app scenarios.

To keep current on status updates, consult flutter#146957.

Add to a custom Xcode target

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.

How to remove Swift Package Manager integration

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:

  1. Turn off Swift Package Manager.

  2. Clean your project:

    flutter clean
  3. Open your app (ios/Runner.xcworkspace or macos/Runner.xcworkspace) in Xcode.

  4. Navigate to Package Dependencies for the project.

  5. 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" %}

  6. Navigate to Frameworks, Libraries, and Embedded Content for the Runner target.

  7. 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" %}

  8. Go to Product > Scheme > Edit Scheme.

  9. Expand the Build section in the left side bar.

  10. Click Pre-actions.

  11. Expand Run Prepare Flutter Framework Script.

  12. 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" %}

How to use a Swift Package Manager Flutter plugin that requires a higher OS version

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:

  1. Open your app (ios/Runner.xcworkspace or macos/Runner.xcworkspace) in Xcode.

  2. 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" %}

  3. If you updated your iOS app's Minimum Deployments, regenerate the iOS project's configuration files:

    flutter build ios --config-only
  4. If you updated your macOS app's Minimum Deployments, regenerate the macOS project's configuration files:

    flutter build macos --config-only