-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add Swift Package Manager as new opt-in feature for iOS and macOS #146256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Instructions on how to use Swift Package Manager - WIP (Not final)Enable Swift Package ManagerEnable Swift Package ManagerRun the following command: Disable Swift Package ManagerDisable Swift Package ManagerDisabling Swift Package Manager will cause Flutter to use CocoaPods for all dependencies. However, Swift Package Manager will remain intregrated with your project. To remove integration, follow "How to remove Swift Package Manager integration" instructions below. Disable for a single projectIn the project's pubspec.yaml, under the # The following section is specific to Flutter packages.
flutter:
disable-swift-package-manager: trueDisable globally for all projectsRun the following command: Converting an existing Objective-C Flutter Plugin to a Swift PackageConverting an existing Objective-C Flutter Plugin to a Swift PackageReplace
/plugin_name/plugin_name_ios/ios/plugin_name_ios
/plugin_name/plugin_name_ios/ios/plugin_name_ios/Package.swift /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources/plugin_name_ios /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources/plugin_name_ios/include /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources/plugin_name_ios/include/plugin_name_ios /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources/plugin_name_ios/include/plugin_name_ios/.gitkeep
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "plugin_name_ios",
platforms: [
.iOS("12.0"),
.macOS("10.14")
],
products: [
// If the plugin name contains "_", replace with "-" for the library name
.library(name: "plugin-name-ios", targets: ["plugin_name_ios"])
],
dependencies: [],
targets: [
.target(
name: "plugin_name_ios",
dependencies: [],
resources: [
// If your plugin requires a privacy manifest, for example if it uses any required
// reason APIs, update the PrivacyInfo.xcprivacy file to describe your plugin's
// privacy impact, and then uncomment these lines. For more information, see
// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
// .process("PrivacyInfo.xcprivacy"),
// If you have other resources that need to be bundled with your plugin, refer to
// the following instructions to add them:
// https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
],
cSettings: [
.headerSearchPath("include/plugin_name_ios")
]
)
]
)
resources: [
// If your plugin requires a privacy manifest, for example if it uses any required
// reason APIs, update the PrivacyInfo.xcprivacy file to describe your plugin's
// privacy impact, and then uncomment these lines. For more information, see
// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
- // .process("PrivacyInfo.xcprivacy"),
+ .process("PrivacyInfo.xcprivacy"),
// If you have other resources that need to be bundled with your plugin, refer to
// the following instructions to add them:
// https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
],
For example, if the following changes were made: Within - #import "PublicHeaderFile.h"
+ #import "./include/plugin_name_ios/PublicHeaderFile.h"
- objcHeaderOut: 'ios/Classes/messages.g.h',
+ objcHeaderOut: 'ios/plugin_name_ios/Sources/plugin_name_ios/messages.g.h',
- objcSourceOut: 'ios/Classes/messages.g.m',
+ objcSourceOut: 'ios/plugin_name_ios/Sources/plugin_name_ios/messages.g.m',If your objcHeaderOut: 'ios/plugin_name_ios/Sources/plugin_name_ios/include/plugin_name_ios/messages.g.h',
objcSourceOut: 'ios/plugin_name_ios/Sources/plugin_name_ios/messages.g.m',
+ objcOptions: ObjcOptions(
+ headerIncludePath: './include/plugin_name_ios/messages.g.h',
+ ),
- s.source_files = 'Classes/**/*.{h,m}'
+ s.source_files = 'plugin_name_ios/Sources/plugin_name_ios/**/*.{h,m}'
- s.public_header_files = 'Classes/**/*.h'
+ s.public_header_files = 'plugin_name_ios/Sources/plugin_name_ios/include/**/*.h'
- s.module_map = 'Classes/cocoapods_plugin_name_ios.modulemap'
+ s.module_map = 'plugin_name_ios/Sources/plugin_name_ios/include/cocoapods_plugin_name_ios.modulemap'
- s.resource_bundles = {'plugin_name_ios_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
+ s.resource_bundles = {'plugin_name_ios_privacy' => ['plugin_name_ios/Sources/plugin_name_ios/PrivacyInfo.xcprivacy']}
#if SWIFT_PACKAGE
NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
#else
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
#endif
NSURL *imageURL = [bundle URLForResource:@"image" withExtension:@"jpg"];
!.gitkeepThen run
Converting an existing Swift Flutter Plugin to a Swift PackageConverting an existing Swift Flutter Plugin to a Swift PackageReplace
/plugin_name/plugin_name_ios/ios/plugin_name_ios
/plugin_name/plugin_name_ios/ios/plugin_name_ios/Package.swift /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources /plugin_name/plugin_name_ios/ios/plugin_name_ios/Sources/plugin_name_ios
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "plugin_name_ios",
platforms: [
.iOS("12.0"),
.macOS("10.14")
],
products: [
// If the plugin name contains "_", replace with "-" for the library name
.library(name: "plugin-name-ios", targets: ["plugin_name_ios"])
],
dependencies: [],
targets: [
.target(
name: "plugin_name_ios",
dependencies: [],
resources: [
// If your plugin requires a privacy manifest, for example if it uses any required
// reason APIs, update the PrivacyInfo.xcprivacy file to describe your plugin's
// privacy impact, and then uncomment these lines. For more information, see
// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
// .process("PrivacyInfo.xcprivacy"),
// If you have other resources that need to be bundled with your plugin, refer to
// the following instructions to add them:
// https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
]
)
]
)
resources: [
// If your plugin requires a privacy manifest, for example if it uses any required
// reason APIs, update the PrivacyInfo.xcprivacy file to describe your plugin's
// privacy impact, and then uncomment these lines. For more information, see
// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
- // .process("PrivacyInfo.xcprivacy"),
+ .process("PrivacyInfo.xcprivacy"),
// If you have other resources that need to be bundled with your plugin, refer to
// the following instructions to add them:
// https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
],
- swiftOut: 'ios/Classes/messages.g.swift',
+ swiftOut: 'ios/plugin_name_ios/Sources/plugin_name_ios/messages.g.swift',
- s.source_files = 'Classes/**/*.swift'
+ s.source_files = 'plugin_name_ios/Sources/plugin_name_ios/**/*.swift'
- s.resource_bundles = {'plugin_name_ios_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
+ s.resource_bundles = {'plugin_name_ios_privacy' => ['plugin_name_ios/Sources/plugin_name_ios/PrivacyInfo.xcprivacy']}
#if SWIFT_PACKAGE
let settingsURL = Bundle.module.url(forResource: "image", withExtension: "jpg")
#else
let settingsURL = Bundle(for: Self.self).url(forResource: "image", withExtension: "jpg")
#endif
Updating unit tests in plugin example appUpdating unit tests in plugin example appIf your plugin has native XCTests, you may need to update them to work with Swift Package Manger if one of the following is true:
target 'RunnerTests' do
inherit! :search_paths
- pod 'OCMock', '3.5'
end`Then in the terminal, run
Note: OCMock uses unsafe build flags and cant only be used if targeted by commit.
How to manually add Swift Package Manager integration to iOS project if Flutter CLI fails to automatically migrateHow to manually add Swift Package Manager integration to iOS project if Flutter CLI fails to automatically migratePlease file a bug before manually migrating to help the Flutter team improve the automatic migration. Please include the error message you received and consider including a copy of the of the following files in your bug report:
Part 1: Add FlutterGeneratedPluginSwiftPackage Package Dependency
Part 2: Add Run Prepare Flutter Framework Script Pre-ActionThe following must be completed for each flavor.
Part 3: Run app
How to manually add Swift Package Manager integration to macOS project if Flutter CLI fails to automatically migrateHow to manually add Swift Package Manager integration to macOS project if Flutter CLI fails to automatically migratePlease file a bug before manually migrating to help the Flutter team improve the automatic migration. Please include the error message you received and consider including a copy of the of the following files in your bug report:
Part 1: Add FlutterGeneratedPluginSwiftPackage Package Dependency
Part 2: Add Run Prepare Flutter Framework Script Pre-ActionThe following must be completed for each flavor.
Part 3: Run app
How to use a Swift Package Flutter plugin that requires a higher OS versionIf a Swift Package Flutter plugin requires a higher OS version than the project, you may get an error like this: To still be able to use the plugin, you'll need to increase the Minimum Deployment of your project to match. Keep in mind, this will increase the minimum OS version that your app can run on. How to add Swift Package Manager integration to a custom targetHow to add Swift Package Manager integration to a custom targetFollow the steps in In Part 1, Step 6 use your custom target instead of the Flutter target. In Part 2, Step 6 use your custom target instead of the Flutter target. How to remove Swift Package Manager integrationHow to remove Swift Package Manager integration
FAQSComing soon... |
What's the use case for project-level control? It would be nice if we could minimize the number of knobs and switches that we have to support. |
By default, it'll use CocoaPods and Swift Package Manager together, but they don't actually work together. For example, if a SPM-supported plugin and CocoaPod-only plugin is being used and both plugins have a same transitive dependency, it can cause errors about duplicate symbols or redefined modules. The only workaround then is to remove one of the plugins or fallback to just using CocoaPods only (aka via disabling SPM in the pubspec.yaml). Hypothetically could disable it globally, but that would be annoying to have to run the enable/disable command per project. |
|
Ah right, I forgot about that limitation. Makes sense! |
|
I converted |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reviewed the Xcode project editor or the tests yet, but posting comments for the rest now. Overall this looks really good!
packages/flutter_tools/lib/src/macos/swift_package_manager.dart
Outdated
Show resolved
Hide resolved
| {{targets}} | ||
| ] | ||
| ) | ||
| '''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're regenerating this every time plugins change, is there a way for users to make edits (like use_frameworks! and the like in the current pod file)? Or is that not something that will be necessary for SPM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this file will not really be editable by the user since it's generated. Unfortunately, swift packages don't have as much control as CocoaPods did.
So use_frameworks! would tell CocoaPods to use dynamic libraries rather than static - that's not possible with SPM. You can define whether the package itself is static or dynamic, but not dependencies.
Also, FYI, SPM recommends not setting what type and letting Xcode decide. It seems to default to static.
I did confirm that privacy manifest are still included in the app even if statically linked. SPM puts them in a .bundle in the Runner.app directory. I also tested that Xcode's Generate Report archival process found them.
flutter/flutter@fb110b9...98685a0 2024-04-19 [email protected] Replace CocoaPods deprecated `exists?` with `exist?` (flutter/flutter#147056) 2024-04-19 [email protected] Roll Flutter Engine from 4ed7a2d6aed9 to 7fafbbf17c02 (2 revisions) (flutter/flutter#147046) 2024-04-19 [email protected] Roll Flutter Engine from 25d773ea90c4 to 4ed7a2d6aed9 (3 revisions) (flutter/flutter#147038) 2024-04-19 [email protected] Update link branches to `main` (continued) (flutter/flutter#146985) 2024-04-19 [email protected] Roll Flutter Engine from b6234dd1984e to 25d773ea90c4 (1 revision) (flutter/flutter#147035) 2024-04-19 [email protected] Roll Flutter Engine from ff471881e90a to b6234dd1984e (2 revisions) (flutter/flutter#147029) 2024-04-19 [email protected] Roll Flutter Engine from 442d14a7e840 to ff471881e90a (1 revision) (flutter/flutter#147025) 2024-04-19 [email protected] Roll Flutter Engine from 6e4a15d31769 to 442d14a7e840 (2 revisions) (flutter/flutter#147023) 2024-04-19 [email protected] Opt out users from GA3 if opted out of GA4 (flutter/flutter#146453) 2024-04-19 [email protected] Roll Flutter Engine from 61bf47d129bb to 6e4a15d31769 (1 revision) (flutter/flutter#147022) 2024-04-18 [email protected] Roll Flutter Engine from 13a6ce419664 to 61bf47d129bb (4 revisions) (flutter/flutter#147017) 2024-04-18 [email protected] Add a breadcrumb for the pub autoroller (flutter/flutter#146786) 2024-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Add generic type for result in PopScope (#139164)" (flutter/flutter#147015) 2024-04-18 [email protected] Redundant message fix (flutter/flutter#143978) 2024-04-18 [email protected] Clean up flutterRoot (flutter/flutter#147010) 2024-04-18 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.1 to 4.3.2 (flutter/flutter#147011) 2024-04-18 [email protected] Add Swift Package Manager as new opt-in feature for iOS and macOS (flutter/flutter#146256) 2024-04-18 [email protected] Refactor framework coverage tests (flutter/flutter#146210) 2024-04-18 [email protected] Roll Flutter Engine from 46ff024bff10 to 13a6ce419664 (3 revisions) (flutter/flutter#147006) 2024-04-18 [email protected] Changing the renderer on the web target should change its build key. (flutter/flutter#147003) 2024-04-18 [email protected] Roll Flutter Engine from 6abfa565a9f9 to 46ff024bff10 (1 revision) (flutter/flutter#147005) 2024-04-18 [email protected] Add generic type for result in PopScope (flutter/flutter#139164) 2024-04-18 [email protected] Roll Flutter Engine from aa6f7411c219 to 6abfa565a9f9 (1 revision) (flutter/flutter#147002) 2024-04-18 [email protected] [tools] Make SnapshotType.platform non-nullable (flutter/flutter#146958) 2024-04-18 [email protected] Roll Flutter Engine from b8e802515b5a to aa6f7411c219 (1 revision) (flutter/flutter#146996) 2024-04-18 [email protected] Roll Flutter Engine from 2c3e9c8bfce6 to b8e802515b5a (2 revisions) (flutter/flutter#146993) 2024-04-18 [email protected] Roll Packages from d39830e to 0e3809d (9 revisions) (flutter/flutter#146992) 2024-04-18 [email protected] Fix memory leaks in navigation rail (flutter/flutter#146988) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Xcode 15 will be required for iOS App Store submission > Please note that as of April 2024 all iOS and iPadOS apps submitted to the App Store must be built with a minimum of Xcode 15 and the iOS 17 SDK. https://developer.apple.com/ios/submit/ And will also be required for Swift Package Manager support flutter#146256. We could swap to "required" but macOS developers don't technically need to upgrade. We can let the Store itself enforce its policies. And we can swap to Xcode 15 "required" when SPM adoption is further along. Part of flutter#144582
) Convert `ProjectMigration.run()` and `ProjectMigrator.migrate()` to be async. Needed for Swift Package Manager migration, which requires some async processes: flutter#146256
…utter#146256) This PR adds initial support for Swift Package Manager (SPM). Users must opt in. Only compatible with Xcode 15+. Fixes flutter#146369. ## Included Features This PR includes the following features: * Enabling SPM via config `flutter config --enable-swift-package-manager` * Disabling SPM via config (will disable for all projects) `flutter config --no-enable-swift-package-manager` * Disabling SPM via pubspec.yaml (will disable for the specific project) ``` flutter: disable-swift-package-manager: true ``` * Migrating existing apps to add SPM integration if using a Flutter plugin with a Package.swift * Generates a Swift Package (named `FlutterGeneratedPluginSwiftPackage`) that handles Flutter SPM-compatible plugin dependencies. Generated package is added to the Xcode project. * Error parsing of common errors that may occur due to using CocoaPods and Swift Package Manager together * Tool will print warnings when using all Swift Package plugins and encourage you to remove CocoaPods This PR also converts `integration_test` and `integration_test_macos` plugins to be both Swift Packages and CocoaPod Pods. ## How it Works The Flutter CLI will generate a Swift Package called `FlutterGeneratedPluginSwiftPackage`, which will have local dependencies on all Swift Package compatible Flutter plugins. The `FlutterGeneratedPluginSwiftPackage` package will be added to the Xcode project via altering of the `project.pbxproj`. In addition, a "Pre-action" script will be added via altering of the `Runner.xcscheme`. This script will invoke the flutter tool to copy the Flutter/FlutterMacOS framework to the `BUILT_PRODUCTS_DIR` directory before the build starts. This is needed because plugins need to be linked to the Flutter framework and fortunately Swift Package Manager automatically uses `BUILT_PRODUCTS_DIR` as a framework search path. CocoaPods will continue to run and be used to support non-Swift Package compatible Flutter plugins. ## Not Included Features It does not include the following (will be added in future PRs): * Create plugin template * Create app template * Add-to-App integration
…ift Package Manager (#6557) Tests new Swift Package Manager feature added in flutter/flutter#146256. Fixes flutter/flutter#146901.
flutter/flutter@fb110b9...98685a0 2024-04-19 [email protected] Replace CocoaPods deprecated `exists?` with `exist?` (flutter/flutter#147056) 2024-04-19 [email protected] Roll Flutter Engine from 4ed7a2d6aed9 to 7fafbbf17c02 (2 revisions) (flutter/flutter#147046) 2024-04-19 [email protected] Roll Flutter Engine from 25d773ea90c4 to 4ed7a2d6aed9 (3 revisions) (flutter/flutter#147038) 2024-04-19 [email protected] Update link branches to `main` (continued) (flutter/flutter#146985) 2024-04-19 [email protected] Roll Flutter Engine from b6234dd1984e to 25d773ea90c4 (1 revision) (flutter/flutter#147035) 2024-04-19 [email protected] Roll Flutter Engine from ff471881e90a to b6234dd1984e (2 revisions) (flutter/flutter#147029) 2024-04-19 [email protected] Roll Flutter Engine from 442d14a7e840 to ff471881e90a (1 revision) (flutter/flutter#147025) 2024-04-19 [email protected] Roll Flutter Engine from 6e4a15d31769 to 442d14a7e840 (2 revisions) (flutter/flutter#147023) 2024-04-19 [email protected] Opt out users from GA3 if opted out of GA4 (flutter/flutter#146453) 2024-04-19 [email protected] Roll Flutter Engine from 61bf47d129bb to 6e4a15d31769 (1 revision) (flutter/flutter#147022) 2024-04-18 [email protected] Roll Flutter Engine from 13a6ce419664 to 61bf47d129bb (4 revisions) (flutter/flutter#147017) 2024-04-18 [email protected] Add a breadcrumb for the pub autoroller (flutter/flutter#146786) 2024-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Add generic type for result in PopScope (#139164)" (flutter/flutter#147015) 2024-04-18 [email protected] Redundant message fix (flutter/flutter#143978) 2024-04-18 [email protected] Clean up flutterRoot (flutter/flutter#147010) 2024-04-18 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.1 to 4.3.2 (flutter/flutter#147011) 2024-04-18 [email protected] Add Swift Package Manager as new opt-in feature for iOS and macOS (flutter/flutter#146256) 2024-04-18 [email protected] Refactor framework coverage tests (flutter/flutter#146210) 2024-04-18 [email protected] Roll Flutter Engine from 46ff024bff10 to 13a6ce419664 (3 revisions) (flutter/flutter#147006) 2024-04-18 [email protected] Changing the renderer on the web target should change its build key. (flutter/flutter#147003) 2024-04-18 [email protected] Roll Flutter Engine from 6abfa565a9f9 to 46ff024bff10 (1 revision) (flutter/flutter#147005) 2024-04-18 [email protected] Add generic type for result in PopScope (flutter/flutter#139164) 2024-04-18 [email protected] Roll Flutter Engine from aa6f7411c219 to 6abfa565a9f9 (1 revision) (flutter/flutter#147002) 2024-04-18 [email protected] [tools] Make SnapshotType.platform non-nullable (flutter/flutter#146958) 2024-04-18 [email protected] Roll Flutter Engine from b8e802515b5a to aa6f7411c219 (1 revision) (flutter/flutter#146996) 2024-04-18 [email protected] Roll Flutter Engine from 2c3e9c8bfce6 to b8e802515b5a (2 revisions) (flutter/flutter#146993) 2024-04-18 [email protected] Roll Packages from d39830e to 0e3809d (9 revisions) (flutter/flutter#146992) 2024-04-18 [email protected] Fix memory leaks in navigation rail (flutter/flutter#146988) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ift Package Manager (flutter#6557) Tests new Swift Package Manager feature added in flutter/flutter#146256. Fixes flutter/flutter#146901.
Flutter iOS/macOS is migrating to Swift Package Manager for native dependencies. This is an experimental feature this isn't ready yet for app developers. However, plugin authors should add Swift Package Manager support to their packages. The faster plugin authors add SwiftPM support, the sooner we can drop CocoaPods (and make it easier to install Flutter iOS!). There's [~10K Flutter iOS plugins](https://gist.github.com/loic-sharma/891a358f8abab36133e8a9395f719296) that'll need to migrate, so we really need the plugin migration docs to be as easy to follow as possible. Any and all feedback is appreciated! :) This is based off @vashworth's [guide](flutter/flutter#146256 (comment)). Question for reviewers: What do you think of the doc structure? Should we rearrange things to make it clearer that some sections are to be followed when things go wrong? Or is the current structure clear enough? Preview URLs: 1. [Swift Package Manager for app developers](https://flutter-docs-prod--pr10827-spm-compatibility-ilxd3b00.web.app/packages-and-plugins/swift-package-manager/for-app-developers) 2. [Swift Package Manager for plugin authors ](https://flutter-docs-prod--pr10827-spm-compatibility-ilxd3b00.web.app/packages-and-plugins/swift-package-manager/for-plugin-authors) Part of flutter/flutter#126005 ## Presubmit checklist - [ ] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [x] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer.













This PR adds initial support for Swift Package Manager (SPM). Users must opt in. Only compatible with Xcode 15+.
Fixes #146369.
Included Features
This PR includes the following features:
flutter config --enable-swift-package-managerflutter config --no-enable-swift-package-managerFlutterGeneratedPluginSwiftPackage) that handles Flutter SPM-compatible plugin dependencies. Generated package is added to the Xcode project.This PR also converts
integration_testandintegration_test_macosplugins to be both Swift Packages and CocoaPod Pods.How it Works
The Flutter CLI will generate a Swift Package called
FlutterGeneratedPluginSwiftPackage, which will have local dependencies on all Swift Package compatible Flutter plugins.The
FlutterGeneratedPluginSwiftPackagepackage will be added to the Xcode project via altering of theproject.pbxproj.In addition, a "Pre-action" script will be added via altering of the
Runner.xcscheme. This script will invoke the flutter tool to copy the Flutter/FlutterMacOS framework to theBUILT_PRODUCTS_DIRdirectory before the build starts. This is needed because plugins need to be linked to the Flutter framework and fortunately Swift Package Manager automatically usesBUILT_PRODUCTS_DIRas a framework search path.CocoaPods will continue to run and be used to support non-Swift Package compatible Flutter plugins.
Not Included Features
It does not include the following (will be added in future PRs):
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.