Skip to content

migrate iOS/macOS to correct SPM structure per Flutter 3.44 docs - #213

Open
sunitaprajapati89 wants to merge 2 commits into
mainfrom
feat/test-spm-support-core
Open

migrate iOS/macOS to correct SPM structure per Flutter 3.44 docs#213
sunitaprajapati89 wants to merge 2 commits into
mainfrom
feat/test-spm-support-core

Conversation

@sunitaprajapati89

Copy link
Copy Markdown
Contributor

Rewrites the Swift Package Manager integration for iOS and macOS to
follow Flutter's official plugin migration guide for Flutter 3.44+.

What changed

Directory structure

Swift sources moved from the flat Classes/ layout to the nested
Swift package structure required by Flutter 3.44's tooling:

Before:
ios/
Package.swift
Classes/*.swift

After:
ios/
segment_analytics/
Package.swift
Sources/
segment_analytics/
*.swift

Package.swift

  • Moved from ios/Package.swift to ios/segment_analytics/Package.swift
    (Flutter 3.44 looks for the manifest at ios/{plugin_name}/Package.swift)
  • Added FlutterFramework as a package and target dependency
    (required so SPM can resolve import Flutter in Swift sources)
  • Library product name changed from segment_analytics to segment-analytics
    (SPM convention: underscores in plugin name become hyphens in product name)
  • Minimum iOS platform bumped from 12.0 to 13.0
    (FlutterFramework itself requires iOS 13.0 minimum)
  • Same changes applied to macos/segment_analytics/Package.swift

CocoaPods (podspec)

Updated s.source_files in both podspecs to point to the new
source location:

Before: Classes/**/*
After: segment_analytics/Sources/segment_analytics/**/*.swift

CocoaPods continues to work unchanged for Flutter < 3.44 users.

Pigeon

Updated build_pigeon_plugins.sh output path to match the new
source directory structure.

.gitignore

Added .build/ and .swiftpm/ to ios/ and macos/ gitignores
to prevent SPM-generated build artifacts from being committed.

How it works

Flutter 3.44+ (SPM):
Flutter 3.44 enables Swift Package Manager by default. Its tooling
scans each plugin for a Package.swift at ios/{plugin_name}/Package.swift.
It generates a FlutterGeneratedPluginSwiftPackage that references
each plugin as a local SPM package and provides the FlutterFramework
dependency at ../FlutterFramework relative to the plugin's ios/
directory. With this structure, segment_analytics is added to
FlutterGeneratedPluginSwiftPackage, removed from Podfile.lock,
and the SPM warning disappears.

Flutter < 3.44 (CocoaPods):
Older Flutter versions use CocoaPods for native dependency management.
CocoaPods reads the .podspec file and compiles the Swift sources
from the path defined in s.source_files. Since we updated that path
to point to the new source location, CocoaPods continues to find and
compile the plugin correctly. No SPM involvement on these versions.

Validation

Tested across two Flutter versions using fvm:

Flutter 3.44.9 — SPM:

  • flutter build ios --debug --simulator produced no SPM warning
  • segment_analytics appeared in FlutterGeneratedPluginSwiftPackage
  • segment_analytics was absent from Podfile.lock (integrated via SPM)
  • Build succeeded ✓

Flutter 3.29.2 — CocoaPods (flutter config --no-enable-swift-package-manager):

  • flutter build ios --debug --simulator produced no SPM warning
  • segment_analytics (0.0.1) present in Podfile.lock confirming
    CocoaPods integration via the updated podspec source path
  • Build succeeded ✓

Sunita Prajapati added 2 commits August 12, 2026 14:57
Add linkedFramework linker settings, use hyphenated library product
name, and set static library type — matching the pattern required for
Flutter's tooling to detect SPM support and avoid falling back to
CocoaPods.
Rewrites the Swift Package Manager integration for iOS and macOS to
follow Flutter's official plugin migration guide for Flutter 3.44+.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant