flutter / flutter/flutter

Consider combining `flutter build ios-framework` and `flutter build macos-framework`

Open
#147,172 2 comments 0 reactions 0 assignees View on GitHub
P2 platform-ios platform-macos team-ios triaged-ios
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

When using Flutter in an add-to-app scenario, the native project it's being added to may support both iOS and macOS. When using `flutter build ios-framework`, it produces iOS-only xcframeworks. When using `flutter build macos-framework`, it produces macOS-only xcframeworks. If you're using a plugin that's both iOS and macOS compatible, like shared_preferences, for example, it'll produce 2 xcframeworks, both named `shared_preferences_foundation.xcframework`, one with iOS arch and one with macOS arch.

If you try to link both versions of `shared_preferences_foundation.xcframework` in Xcode, it only shows one in the interface (although it does link both). Also, it will error when you build with a message like:
```
add_flutter_app/build/macos/framework/Debug/shared_preferences_foundation.xcframework:1:1: While building for iOS Simulator, no library for this platform was found in 'add_flutter_app/build/macos/framework/Debug/shared_preferences_foundation.xcframework'.
```

Would be better for Flutter to produce a single `shared_preferences_foundation.xcframework` with all the architectures.

### Proposal

Perhaps combine the commands into a single `flutter build darwin-framework` that will check if the project supports iOS or macOS or both and then produce the needed xcframeworks with the needed architectures. Also, will need to figure out how to produce the `GeneratedPluginRegistrant`.

For Swift Package Manager [add-to-app scenario](https://github.com/flutter/flutter/issues/146957), this could be a little easier, as you can use a [TargetDependencyCondition](https://developer.apple.com/documentation/packagedescription/targetdependencycondition) to include targets dependencies by platform

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.