Allow Swift Package Manager to be used with Add to App #146957
Labels
P2
Important issues not at the top of the work list
team-ios
Owned by iOS platform team
tool
Affects the "flutter" command-line tool. See also t: labels.
triaged-ios
Triaged by iOS platform team
Build solution for add to app to be able to use Swift Package Manager for plugins.
Design / Proposal
Unfortunately, SPM doesn't really have a way to convert a package into an xcframework like CocoaPods does. It seems at some point there may have been a hacky way to do it, but I was unable to get it to work.
As an alternative, we can create a
FlutterPluginRegistrant
Swift Package that then has dependencies on all the Swift Package plugins and CocoaPod xcframeworks. The tricky part, though, is adding the dependency of the Flutter framework. If a plugin does not have a direct dependency on the Flutter framework, it's not guaranteed to be processed before the plugin compiles, which can cause errors about Flutter header not being found.In order to get around this issue, we could do one of the following:
Option 1 - Use Build Phases
In #146256, we get around this issue by using a pre-build script that copies the Flutter framework into a spot (
BUILT_PRODUCTS_DIR
) Swift Package Manager automatically uses as a framework search path.We could do the same for add to app.
prepare_framework.sh
It would require also adding a post compile/link/embed phase, that copies the Flutter.framework from the
$BUILT_PRODUCTS_DIR
to the${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}
directory and then codesigning it with$EXPANDED_CODE_SIGN_IDENTITY
.copy_and_codesign_framework.sh
This would required
ENABLE_USER_SCRIPT_SANDBOXING
to be set to NO in the project's settings.Option 2 - Parse and alter Package.swift for each plugin
My current plan is instead to inject a dependency at the bottom of each plugin's Package.swift like so:
We also will need to ensure the supported platforms for the plugin are higher than or equal to that of the flutter framework (otherwise Swift Package Manager may give an error).
To do this we can use
swift package dump-package
to convert the Package.swift to JSON to check if the version needs to be updated and then inject some swift code at the bottom of the Package.swift to alter the supported platforms, for example:The text was updated successfully, but these errors were encountered: