Skip to content

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented May 25, 2022

Just the plugins part of #52217. Build the plugin xcframeworks as static frameworks. Flutter.xcframework and App.xcframework are still dylibs.

Previous behavior creates dylibs dynamically linked shared library:

$ flutter build ios-framework
$ $ file build/ios/framework/Debug/url_launcher_ios.xcframework/ios-arm64/url_launcher_ios.framework/url_launcher_ios
build/ios/framework/Debug/url_launcher_ios.xcframework/ios-arm64/url_launcher_ios.framework/url_launcher_ios: Mach-O 64-bit dynamically linked shared library arm64

With --static the plugins are ar archive random library

$ flutter build ios-framework --static
$ file build/ios/framework/Debug/url_launcher_ios.xcframework/ios-arm64/url_launcher_ios.framework/url_launcher_ios
build/ios/framework/Debug/url_launcher_ios.xcframework/ios-arm64/url_launcher_ios.framework/url_launcher_ios: current ar archive random library

I tested this manually by:

  1. Adding a plugin url_launcher: to the sample project pubspec.
  2. Adding a button that launches a URL to the dart code:
@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            await launchUrl(Uri.parse('https://www.google.com'));
          },
          child: Text('Launch URL'),
        ),
      ),
    );
  }
  1. Calling GeneratedPluginRegistrant.register(with: self.flutterEngine!); in the AppDelegate
  2. Linking (not embedding!) the static url_launcher_ios and FlutterPluginRegistrant xcframeworks
    in the Xcode project
		F733C128283DD5C7005295FB /* url_launcher_ios.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = url_launcher_ios.xcframework; path = "Flutter/$(CONFIGURATION)/url_launcher_ios.xcframework"; sourceTree = "<group>"; };
		F733C12B283DD6C4005295FB /* FlutterPluginRegistrant.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = FlutterPluginRegistrant.xcframework; path = "Flutter/$(CONFIGURATION)/FlutterPluginRegistrant.xcframework"; sourceTree = "<group>"; };
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				F733C12C283DD6C4005295FB /* FlutterPluginRegistrant.xcframework in Frameworks */,
				F77F88F1255396AD00309E51 /* App.xcframework in Frameworks */,
				F77F88F2255396AD00309E51 /* Flutter.xcframework in Frameworks */,
				F733C129283DD5C7005295FB /* url_launcher_ios.xcframework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;

etc.

Run the app, tap the button, the URL launches.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. a: existing-apps Integration with existing apps via the add-to-app flow labels May 25, 2022
@jmagman jmagman self-assigned this May 25, 2022
@flutter-dashboard flutter-dashboard bot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label May 25, 2022
'FlutterPluginRegistrant.framework',
'FlutterPluginRegistrant',
);
await _checkStatic(registrantFrameworkPath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlutterPluginRegistrant was already static.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a very optional nits.

@blastmann
Copy link

Can I enable this feature on Flutter 3.0?

@jmagman
Copy link
Member Author

jmagman commented Aug 19, 2022

This is available on 3.1.0-9.0.pre, currently in the beta channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: existing-apps Integration with existing apps via the add-to-app flow c: contributor-productivity Team-specific productivity, code health, technical debt. platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants