diff --git a/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/add-files-to-runner.png b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/add-files-to-runner.png new file mode 100644 index 00000000000..bc126b8bcad Binary files /dev/null and b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/add-files-to-runner.png differ diff --git a/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/copy-full-path.png b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/copy-full-path.png new file mode 100644 index 00000000000..71b77281f7e Binary files /dev/null and b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/copy-full-path.png differ diff --git a/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/reference-files-in-place.png b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/reference-files-in-place.png new file mode 100644 index 00000000000..d9e8d3c80b1 Binary files /dev/null and b/site/web/assets/images/docs/development/packages-and-plugins/swift-package-manager/reference-files-in-place.png differ diff --git a/src/_includes/docs/swift-package-manager/migrate-swift-plugin.md b/src/_includes/docs/swift-package-manager/migrate-swift-plugin.md index 11d51bc6ea4..83694b4eb99 100644 --- a/src/_includes/docs/swift-package-manager/migrate-swift-plugin.md +++ b/src/_includes/docs/swift-package-manager/migrate-swift-plugin.md @@ -59,12 +59,16 @@ The example below uses `ios`, replace `ios` with `macos`/`darwin` as applicable. // If the plugin name contains "_", replace with "-" for the library name. .library(name: "plugin-name", targets: ["plugin_name"]) ], - dependencies: [], + dependencies: [ + .package(name: "FlutterFramework", path: "../FlutterFramework") + ], targets: [ .target( // TODO: Update your target name. name: "plugin_name", - dependencies: [], + dependencies: [ + .product(name: "FlutterFramework", package: "FlutterFramework") + ], resources: [ // TODO: If your plugin requires a privacy manifest // (e.g. if it uses any required reason APIs), update the PrivacyInfo.xcprivacy file @@ -166,6 +170,31 @@ The example below uses `ios`, replace `ios` with `macos`/`darwin` as applicable. 1. Move all files from `ios/Classes` to `ios/plugin_name/Sources/plugin_name`. +1. **New in Flutter 3.41!** Add the FlutterFramework as a dependency and update Dart/Flutter version. + + Update `Package.swift` to include `FlutterFramework`: + + ```swift title="Package.swift" + dependencies: [ + .package(name: "FlutterFramework", path: "../FlutterFramework") + ], + targets: [ + .target( + // TODO: Update your target name. + name: "plugin_name", + dependencies: [ + .product(name: "FlutterFramework", package: "FlutterFramework") + ], + ``` + + In `pubspec.yaml`, update versions to: + + ```yaml title="pubspec.yaml" + environment: + sdk: ^3.11.0 + flutter: ">=3.41.0" + ``` + 1. The `ios/Assets`, `ios/Resources`, and `ios/Classes` directories should now be empty and can be deleted. diff --git a/src/content/packages-and-plugins/swift-package-manager/for-plugin-authors.md b/src/content/packages-and-plugins/swift-package-manager/for-plugin-authors.md index c48c2f80735..022d41b2c33 100644 --- a/src/content/packages-and-plugins/swift-package-manager/for-plugin-authors.md +++ b/src/content/packages-and-plugins/swift-package-manager/for-plugin-authors.md @@ -59,6 +59,58 @@ that have migrated. +## (Optional, but Recommended) Add plugin as local package in example app + +If your plugin includes an example, it is recommended to add the plugin as a local package in the example app. This is not required, but provides better Xcode support when editing the plugin's source code in the example app. See [issue #179032](https://github.com/flutter/flutter/issues/179032). + +### Add plugin as local package + +1. In a terminal navigate to `my_plugin`. + +1. Run the following command to open the example app's workspace in Xcode, (replace `ios` with `macos` if your plugin targets macOS): + +```bash +open example/ios/Runner.xcworkspace +``` + +1. Right click **Flutter** > **Add Files to “Runner”**. + + ![Add Files to Runner](/assets/images/docs/development/packages-and-plugins/swift-package-manager/add-files-to-runner.png) + +1. Select `my_plugin/ios/my_plugin` (or `macos` if your plugin targets macOS). + +1. Make sure “Reference files in place” is selected (it should be the default), and click **Finish**. + + ![Select Reference files in place](/assets/images/docs/development/packages-and-plugins/swift-package-manager/reference-files-in-place.png) + +This adds the plugin as a local package, but it will be referenced by absolute path, which is not desirable for distribution. To change it to a relative path, follow the steps below. + +### Change to relative path + +1. Copy “Full Path” for plugin from the File Inspector. + + ![Copy Full Path](/assets/images/docs/development/packages-and-plugins/swift-package-manager/copy-full-path.png) + +1. In terminal: + `open -a Xcode example/ios/Runner.xcodeproj/project.pbxproj` + +1. Find the following: + ```text + path = [COPIED FULL PATH]; sourceTree = "" + ``` + + For example: + + ```text + path = /Users/username/path/to/my_plugin/ios/my_plugin; sourceTree = "" + ``` + +1. And replace with relative path: + ```text + path = ../../ios/my_plugin; sourceTree = "" + ``` + (Adjust `ios` to `macos` or `darwin` as needed). + ## How to update unit tests in a plugin's example app If your plugin has native XCTests, you might need to update them to work with