-
Notifications
You must be signed in to change notification settings - Fork 6k
Build iOS and macOS Obj-C with -fapplication-extension flag #40332
Conversation
| #if !APPLICATION_EXTENSION_API_ONLY | ||
| if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { | ||
| #endif | ||
| [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to end up sending this if the whole process hosting the extension itself was in the background, thus UIApplication.sharedApplication.applicationState != UIApplicationStateActive if we had access to the sharedApplication? If we sent in "resumed" without checking, might be end up in an engine state where we continue to issue GPU commands while in the background and crash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a race that I bet could happen in the app extension #23175
| } | ||
|
|
||
| - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences { | ||
| #if !APPLICATION_EXTENSION_API_ONLY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be able to fall back to changing UIWindowSceneGeometryPreferencesIOS on self.viewIfLoaded.window.windowScene instead, if that works.
| flutter_cflags_objc = [ | ||
| "-Werror=overriding-method-mismatch", | ||
| "-Werror=undeclared-selector", | ||
| "-fapplication-extension", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be set by a buildroot flag so the engine can be built with or without app extension safety. I put it here for testing.
| defines = [ "FLUTTER_FRAMEWORK=1" ] | ||
| defines = [ | ||
| "FLUTTER_FRAMEWORK=1", | ||
| "APPLICATION_EXTENSION_API_ONLY=1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, this would be set by a buildroot flag.
| ldflags = [ "-Wl,-install_name,@rpath/Flutter.framework/Flutter" ] | ||
| ldflags = [ | ||
| "-Wl,-install_name,@rpath/Flutter.framework/Flutter", | ||
| "-fapplication-extension", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, behind a new flag, etc.
|
Closing in favor of #40972 |
First-pass on allowing engine to be built for app extensions without unsafe APIs. This would allow the engine to be built twice, once for apps and again for app extensions. Note the build rule tweaks are only to allow testing, this would require much more work to output two versions of the framework.
See design doc
Steps to use
In your Flutter SDK check out flutter/flutter@c80ef4768e which is a random commit but matches the same dart version as this branch. Run
flutterto build the tool and download artifacts.In your engine repo check out this branch
gh pr checkout 40332.out/ios_debug_sim_unopt/Flutter.xcframework(orios_debug_sim_unopt_arm64) into the FlutterShare target General > Frameworks and Libraries section. Make sure Embed & Sign is selected in the drop downtest_extension/ios/FlutterShare/Info.plistremove theNSExtensionMainStoryboardkey. Add a new key-valueNSExtensionPrincipalClass=FlutterViewController.@import Flutter;to the totally unusedShareViewController.mor in theFlutterSharetarget build settings add-framework Flutterto Other Linker Flags (you only need to do one of these options).
orRunnerscheme on a simulator to install the app, orflutter runfrom thetest_extensionproject directory. See the demo app run.Choose Test Extension

See the Flutter counter app run in the Share Extension:
Validate
Build/Products/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework/Info.plisttheFlutterEnginekey should be 4965437, which is the engine in your Flutter SDK.Build/Products/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework/Info.plisttheFlutterEnginekey should be 575105f, which is the commit of this PR.