-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from all commits
f1cba09
cfe87b4
ce19db0
a0d9321
936154e
78a1617
3c6f68d
1eeb04a
43fbe63
b1f8285
58fb5f7
9c12c3c
790e5a0
d77cb99
4ca1c4c
bd0849d
3933ab0
7f5d8aa
8308618
458ae72
eb21f14
0a62adc
61cc23e
e40eb01
acdc069
d793b49
3e59825
738c809
007dc52
d2017a6
34260db
7aba034
a366e82
e13857c
0d5b20e
7d21518
9dac737
31c20cb
68b7095
e317958
38acd94
cef90e9
6efe8b4
b32acd0
089af8f
a8ed7f8
48d7466
3b4f10e
7ea241d
db45a7b
219ed26
eac1d51
edf3a3c
3dadda2
35407c9
3f315e2
1112b3e
f7e2f13
115e353
3d6076f
1e3dd40
1f7ed78
ef3be5b
dbde679
0460798
1ed8131
677ae4a
e861981
33bad77
7406fbe
46f40d5
ec32096
d34aeca
b50fdf5
874206f
32a0c1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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'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.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.
oh, good idea!
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.
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!