Skip to content
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

Add Swift Package Manager docs #10827

Merged
merged 76 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f1cba09
Begin import
loic-sharma Jun 27, 2024
cfe87b4
Use tabs for migration guides
loic-sharma Jun 28, 2024
ce19db0
Work
loic-sharma Jun 28, 2024
a0d9321
Formatting
loic-sharma Jun 28, 2024
936154e
Work
loic-sharma Jun 28, 2024
78a1617
Work
loic-sharma Jun 28, 2024
3c6f68d
Work
loic-sharma Jun 28, 2024
1eeb04a
Work
loic-sharma Jun 28, 2024
43fbe63
Start importing images
loic-sharma Jun 28, 2024
b1f8285
Import more images
loic-sharma Jun 28, 2024
58fb5f7
Yay I can write diff files by hand now
loic-sharma Jun 28, 2024
9c12c3c
Link to SPM docs
loic-sharma Jul 1, 2024
790e5a0
Feedback
loic-sharma Jul 1, 2024
d77cb99
Easy feedback
loic-sharma Jul 1, 2024
4ca1c4c
Switch to 'main'
loic-sharma Jul 1, 2024
bd0849d
Fix up Package.swift
loic-sharma Jul 1, 2024
3933ab0
Start switching to bolded menu items
loic-sharma Jul 1, 2024
7f5d8aa
Bold more menu items
loic-sharma Jul 1, 2024
8308618
Bold more menu text
loic-sharma Jul 1, 2024
458ae72
Tweaks
loic-sharma Jul 1, 2024
eb21f14
Fix stuff I missed
loic-sharma Jul 1, 2024
0a62adc
Fix
loic-sharma Jul 1, 2024
61cc23e
Feedback
loic-sharma Jul 1, 2024
e40eb01
Address all feedback
loic-sharma Jul 1, 2024
acdc069
Link to enable SPM
loic-sharma Jul 2, 2024
d793b49
Switch to ASCII art for directory structures
loic-sharma Jul 2, 2024
3e59825
Tweak
loic-sharma Jul 2, 2024
738c809
Make it clearer you might need to modify platforms
loic-sharma Jul 2, 2024
007dc52
Tweaks
loic-sharma Jul 2, 2024
d2017a6
Tweaks
loic-sharma Jul 2, 2024
34260db
Tweaks
loic-sharma Jul 2, 2024
7aba034
Tweaks
loic-sharma Jul 2, 2024
a366e82
Tweak
loic-sharma Jul 2, 2024
e13857c
Tweaks
loic-sharma Jul 2, 2024
0d5b20e
Tweaks
loic-sharma Jul 2, 2024
7d21518
Tweaks
loic-sharma Jul 2, 2024
9dac737
Tweaks
loic-sharma Jul 2, 2024
31c20cb
Tweaks
loic-sharma Jul 2, 2024
68b7095
Tweaks
loic-sharma Jul 2, 2024
e317958
Tweaks
loic-sharma Jul 2, 2024
38acd94
Tweaks
loic-sharma Jul 2, 2024
cef90e9
Tweaks
loic-sharma Jul 2, 2024
6efe8b4
Tweaks
loic-sharma Jul 2, 2024
b32acd0
Tweaks
loic-sharma Jul 2, 2024
089af8f
Improve instructions to update imports
loic-sharma Jul 8, 2024
a8ed7f8
Tweak
loic-sharma Jul 8, 2024
48d7466
Address feedback
loic-sharma Jul 8, 2024
3b4f10e
Feedback
loic-sharma Jul 8, 2024
7ea241d
Switch to warning banner
loic-sharma Jul 9, 2024
db45a7b
Start addressing John's feedback
loic-sharma Jul 10, 2024
219ed26
Address more feedback by John
loic-sharma Jul 10, 2024
eac1d51
Feedback
loic-sharma Jul 11, 2024
edf3a3c
Re-wrap more
loic-sharma Jul 11, 2024
3dadda2
Start Tony feedback
loic-sharma Jul 12, 2024
35407c9
Fix broken link
loic-sharma Jul 12, 2024
3f315e2
Tony feedback: avoid future tense
loic-sharma Jul 12, 2024
1112b3e
Tweak
loic-sharma Jul 12, 2024
f7e2f13
Tweak
loic-sharma Jul 12, 2024
115e353
Tony feedback
loic-sharma Jul 12, 2024
3d6076f
Tony feedback
loic-sharma Jul 12, 2024
1e3dd40
Tony feedback: use fewer warning blocks
loic-sharma Jul 12, 2024
1f7ed78
Tony feedback: use contractions
loic-sharma Jul 12, 2024
ef3be5b
Tony feedback: hemingway pass
loic-sharma Jul 12, 2024
dbde679
Tony feedback: replace enable/disable with turn on/off
loic-sharma Jul 12, 2024
0460798
Tony feedback: replace enable/disable with turn on/off
loic-sharma Jul 12, 2024
1ed8131
Tony feedback: replace enable/disable with turn on/off
loic-sharma Jul 12, 2024
677ae4a
Seth feedback
loic-sharma Jul 16, 2024
e861981
Start Tony feedback; TODO double check I didn't miss anything
loic-sharma Jul 16, 2024
33bad77
Fix link
loic-sharma Jul 16, 2024
7406fbe
Tony feedback
loic-sharma Jul 16, 2024
46f40d5
Clarify this content is only if the auto migration fails
loic-sharma Jul 16, 2024
ec32096
Tony feedback
loic-sharma Jul 16, 2024
d34aeca
Seth feedback
loic-sharma Jul 16, 2024
b50fdf5
Restructure for app developers page ; add auto migration docs
loic-sharma Jul 16, 2024
874206f
Seth feedback
loic-sharma Jul 16, 2024
32a0c1c
Tony feedback
loic-sharma Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/_data/sidenav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,13 @@
permalink: /packages-and-plugins/using-packages
- title: Develop packages & plugins
permalink: /packages-and-plugins/developing-packages
- title: Swift Package Manager
permalink: /packages-and-plugins/swift-package-manager
children:
- title: For app developers
permalink: /packages-and-plugins/swift-package-manager/for-app-developers
Comment on lines +508 to +509
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure app developers would think to go into Packages & plugins
Maybe this should move into Platform integration? Though it would make sense under iOS and macOS, and we don't have a shared category. Whatever you and the tech writers think works best.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good idea!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow response, I'd like to test if I can link to this page twice: once from the packages & plugin section and once from the platform integration section. Will loop back soon!

- title: For plugin authors
permalink: /packages-and-plugins/swift-package-manager/for-plugin-authors
- divider
- title: Flutter Favorites
permalink: /packages-and-plugins/favorites
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## How to turn on Swift Package Manager

Flutter's Swift Package Manager support is turned off by default.
To turn it on:

1. Switch to Flutter's `main` channel:

```sh
flutter channel main
```

2. Make sure you have the latest Flutter SDK:

```sh
flutter upgrade
```

3. Turn on the Swift Package Manager feature:

```sh
flutter config --enable-swift-package-manager
```

Using the Flutter CLI to run an app modifies the project to add Swift Package
Manager integration.
This makes your project download the Swift packages that
your Flutter plugins depend on.

Flutter falls back to CocoaPods for dependencies that do not support Swift
Package Manager yet.

## How to turn off Swift Package Manager

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:::secondary Plugin authors
Plugin authors need to be able to disable and enable SPM for testing.
Otherwise, you likely won't need to disable this.
:::

Copy link
Member Author

@loic-sharma loic-sharma Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I added this and moved the link to file a bug to this box to reduce the number of callouts in this section. Let me know if you have concerns with that

:::secondary Plugin authors
Plugin authors need to turn on and off Flutter's Swift Package Manager
support for testing.
App developers do not need to disable Swift Package Manager support,
unless they are running into issues.
If you find a bug in Flutter's Swift Package Manager support,
[open an issue][].
:::

Disabling Swift Package Manager causes Flutter to use CocoaPods for all
dependencies.
However, Swift Package Manager remains integrated with your project.
To remove Swift Package Manager integration completely from your project,
follow the [How to remove Swift Package Manager integration][removeSPM]
instructions.

### Turn off for a single project

In the project's `pubspec.yaml` file, under the `flutter` section,
add `disable-swift-package-manager: true`.
```yaml title="pubspec.yaml"
# The following section is specific to Flutter packages.
flutter:
disable-swift-package-manager: true
```
This turns off Swift Package Manager for all contributors to this project.
### Turn off globally for all projects
Run the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is worth pointing out, but it would need to be disabled for all contributors to an app as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! I'll leave this open for now in case folks have suggestions on the wording.

```sh
flutter config --no-enable-swift-package-manager
```
This turns off Swift Package Manager for the current user.
If a project is incompatible with Swift Package Manager, all contributors
need to run this command.
[removeSPM]: /packages-and-plugins/swift-package-manager/for-app-developers#how-to-remove-swift-package-manager-integration
[open an issue]: {{site.github}}/flutter/flutter/issues/new?template=2_bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Once you [turn on Swift Package Manager][], the Flutter CLI tries to migrate
your project to use Swift Package Manager the next time you run your app
using the CLI.

However, the Flutter CLI tool might be unable to migrate your project
automatically if there are unexpected modifications.

If the automatic migration fails, use the steps below to add Swift Package
Manager integration to a project manually.

Before migrating manually, [file an issue][]; this helps the Flutter team
improve the automatic migration process.
Include the error message and, if possible, include a copy of
the following files in your issue:

* `ios/Runner.xcodeproj/project.pbxproj`
* `ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme`
(or the xcsheme for the flavor used)

### Step 1: Add FlutterGeneratedPluginSwiftPackage Package Dependency {:.no_toc}

1. Open your app (`ios/Runner.xcworkspace`) in Xcode.
2. Navigate to **Package Dependencies** for the project.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/package-dependencies.png",
caption:"The project's package dependencies" %}

3. Click <span class="material-symbols-outlined">add</span>.
4. In the dialog that opens, click **Add Local...**.
5. Navigate to `ios/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage`
and click **Add Package**.
6. Ensure that it's added to the `Runner` target and click **Add Package**.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/choose-package-products.png",
caption:"Ensure that the package is added to the `Runner` target" %}

7. Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks,
Libraries, and Embedded Content**.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/add-generated-framework.png",
caption:"Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" %}

### Step 2: Add Run Prepare Flutter Framework Script Pre-Action {:.no_toc}

**The following steps must be completed for each flavor.**

1. Go to **Product > Scheme > Edit Scheme**.
2. Expand the **Build** section in the left side bar.
3. Click **Pre-actions**.
4. Click <span class="material-symbols-outlined">add</span> and
select **New Run Script Action** from the menu.
5. Click the **Run Script** title and change it to:

```plaintext
Run Prepare Flutter Framework Script
```

6. Change the **Provide build settings from** to the `Runner` app.
7. Input the following in the text box:

```sh
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" prepare
```

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png",
caption:"Add **Run Prepare Flutter Framework Script** build pre-action" %}

### Step 3: Run app {:.no_toc}

1. Run the app in Xcode.
2. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png",
caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}

3. Ensure that the app runs on the command line with `flutter run`.

[turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
[file an issue]: {{site.github}}/flutter/flutter/issues/new?template=2_bug.yml
38 changes: 38 additions & 0 deletions src/_includes/docs/swift-package-manager/migrate-ios-project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Once you [turn on Swift Package Manager][], the Flutter CLI tries to migrate
your project the next time you run your app using the CLI.
This migration updates your Xcode project to use Swift Package Manager to
add Flutter plugin dependencies.

To migrate your project:

1. [Turn on Swift Package Manager][].

2. Run the iOS app using the Flutter CLI.

If your iOS project doesn't have Swift Package Manager integration yet, the
Flutter CLI tries to migrate your project and outputs something like:

```console
$ flutter run
Adding Swift Package Manager integration...
```

The automatic iOS migration modifies the
`ios/Runner.xcodeproj/project.pbxproj` and
`ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme` files.

3. If the Flutter CLI's automatic migration fails, follow the steps in
[add Swift Package Manager integration manually][manualIntegration].

[Optional] To check if your project is migrated:

1. Run the app in Xcode.
2. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png",
caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}

[Turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
[manualIntegration]: /packages-and-plugins/swift-package-manager/for-app-developers/#add-to-a-flutter-app-manually
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Once you [turn on Swift Package Manager][], the Flutter CLI tries to migrate
your project to use Swift Package Manager the next time you run your app
using the CLI.

However, the Flutter CLI tool might be unable to migrate your project
automatically if there are unexpected modifications.

If the automatic migration fails, use the steps below to add Swift Package
Manager integration to a project manually.

Before migrating manually, [file an issue][]; this helps the Flutter team
improve the automatic migration process.
Include the error message and, if possible, include a copy of
the following files in your issue:

* `macos/Runner.xcodeproj/project.pbxproj`
* `macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme`
(or the xcscheme for the flavor used)

### Step 1: Add FlutterGeneratedPluginSwiftPackage Package Dependency {:.no_toc}

1. Open your app (`macos/Runner.xcworkspace`) in Xcode.
2. Navigate to **Package Dependencies** for the project.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/package-dependencies.png",
caption:"The project's package dependencies" %}

3. Click <span class="material-symbols-outlined">add</span>.
4. In the dialog that opens, click the **Add Local...**.
5. Navigate to `macos/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage`
and click the **Add Package**.
6. Ensure that it's added to the Runner Target and click **Add Package**.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/choose-package-products.png",
caption:"Ensure that the package is added to the `Runner` target" %}

7. Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks,
Libraries, and Embedded Content**.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/add-generated-framework.png",
caption:"Ensure that `FlutterGeneratedPluginSwiftPackage` was added to **Frameworks, Libraries, and Embedded Content**" %}

### Step 2: Add Run Prepare Flutter Framework Script Pre-Action {:.no_toc}

**The following steps must be completed for each flavor.**

1. Go to **Product > Scheme > Edit Scheme**.
2. Expand the **Build** section in the left side bar.
3. Click **Pre-actions**.
4. Click the <span class="material-symbols-outlined">add</span> button
and select **New Run Script Action** from the menu.
5. Click the **Run Script** title and change it to:

```plaintext
Run Prepare Flutter Framework Script
```

6. Change the **Provide build settings from** to the `Runner` target.
7. Input the following in the text box:

```sh
"$FLUTTER_ROOT"/packages/flutter_tools/bin/macos_assemble.sh prepare
```

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/add-flutter-pre-action.png",
caption:"Add **Run Prepare Flutter Framework Script** build pre-action" %}

### Step 3: Run app {:.no_toc}

1. Run the app in Xcode.
2. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png",
caption:"Ensure `Run Prepare Flutter Framework Script` runs as a pre-action" %}

3. Ensure that the app runs on the command line with `flutter run`.

[turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
[file an issue]: {{site.github}}/flutter/flutter/issues/new?template=2_bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Once you [turn on Swift Package Manager][], the Flutter CLI tries to migrate
your project the next time you run your app using the CLI.
This migration updates your Xcode project to use Swift Package Manager to
add Flutter plugin dependencies.

To migrate your project:

1. [Turn on Swift Package Manager][].

2. Run the macOS app using the Flutter CLI.

If your macOS project doesn't have Swift Package Manager integration yet, the
Flutter CLI tries to migrate your project and outputs something like:

```console
$ flutter run -d macos
Adding Swift Package Manager integration...
```

The automatic iOS migration modifies the
`macos/Runner.xcodeproj/project.pbxproj` and
`macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme` files.

3. If the Flutter CLI's automatic migration fails, follow the steps in
[add Swift Package Manager integration manually][manualIntegration].

[Optional] To check if your project is migrated:

1. Run the app in Xcode.
2. Ensure that **Run Prepare Flutter Framework Script** runs as a pre-action
and that `FlutterGeneratedPluginSwiftPackage` is a target dependency.

{% render docs/captioned-image.liquid,
image:"development/packages-and-plugins/swift-package-manager/flutter-pre-action-build-log.png",
caption:"Ensure **Run Prepare Flutter Framework Script** runs as a pre-action" %}

[Turn on Swift Package Manager]: /packages-and-plugins/swift-package-manager/for-app-developers/#how-to-turn-on-swift-package-manager
[manualIntegration]: /packages-and-plugins/swift-package-manager/for-app-developers/#add-to-a-flutter-app-manually
Loading
Loading