flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
161.98k stars 26.59k forks source link

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

Open vashworth opened 1 week ago

vashworth commented 1 week ago

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, this could be a little easier, as you can use a TargetDependencyCondition to include targets dependencies by platform

vashworth commented 1 week ago

May want to consider doing before adding official documentation on flutter build macos-framework.

jmagman commented 1 week ago

That's a good idea. I always get caught up on the naming here. A lot of folks don't know what "darwin" means. We could alias both flutter build ios-framework and flutter build macos-framework to it though.