Description
Use case
The biggest problem with adopting SwiftPM in Flutter is that plugins have a dependency on Flutter, however, they need to use a local version of the Flutter framework. This poses a problem because the local path may vary per user, so it’s impossible to define in a plugin’s Package.swift.
To solve this problem, the current solution involves using a "Pre-action" bash script. This script invokes the flutter tool to copy the Flutter/FlutterMacOS framework to the BUILT_PRODUCTS_DIR directory before the build starts. Fortunately Swift Package Manager automatically uses BUILT_PRODUCTS_DIR as a framework search path, so when plugins compile, the Flutter framework is available.
Although Flutter uses caching to minimize the impact of using a pre-action on build times, pre-actions have a perception of being slow since they run before every build. They have also been known to be flakey in the past.
On the plugins side, the dependency on Flutter is not defined in the Package.swift and is implicit.
Due to only having an implicit dependency on Flutter, Flutter plugin Swift Packages cannot be built or tested independently like Swift Packages normally can (using commands like swift build or swift test.
Proposal
Instead, we can use local package overrides to handle the Flutter framework. Plugins will define a dependency on a remote Flutter framework, but when run through the Flutter CLI or Xcode, Xcode will override the dependency with a local version of the Flutter framework.
See flutter.dev/go/swift-package-manager-plugins-v3 for details