Repository navigation
Let apps skip building the native library on platforms they choose - #56
Merged
Merged
Conversation
cnativeapi's build hook compiled and bundled the library for every target, including Android and iOS builds of apps that call nativeapi only on desktop. An app can now list the platforms to leave it out on in its pubspec, as hooks.user_defines.cnativeapi.skip_platforms. Nothing changes for apps that don't set it.
Member
|
Thanks @dbebawy for the implementation, tests, and detailed validation! I independently verified the Android release app on an emulator and the iOS debug app on a simulator, plus the unsigned iOS device release bundle. With skipping enabled, the native library is omitted, the app still renders its first frame, and native calls throw I also verified real Dart processes on macOS, Windows, and Linux, including switching skipping on and off to check cached outputs. All 9 Dart CI checks passed, and this is now merged as 25ab2518, closing #55. Thanks again! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #55
An app that calls nativeapi only on desktop, such as one using
window_manager, still compiles and shipscnativeapiin its Android and iOS builds. This adds an opt-in setting to leave the library out on the platforms an app lists:Nothing changes for apps that don't set it. On a skipped platform, importing the package works and calling into nativeapi throws
ArgumentError. A value that isn't a list of known platform names fails the build with a message naming the setting.Changes
hook/build.dart: return before compiling when the target is listed.README.md: how to use it, and that calls on a skipped platform throw.test/build_hook_test.dart: 15 cases, usingtestCodeBuildHook. They compile no C++ themselves, thoughflutter teststill runs the package's build hook first. CI'smelos run testwill pick upcnativeapi, which had notest/directory before.I left the changelog alone, since it goes with the version bump at release.
Measurements
A
flutter createapp withwindow_manager0.7.1 and Flutter 3.50.0 (run):skip_platforms: [android, ios]cnativeapibinary, iOS releaseValidation
dart formatanddart analyzeonhookandtestpass on Linux, macOS and Windows (run). That run's two iOS launch checks failed, with and without the setting, because the check only read console output. The later run above fixes the check, and its four builds pass.WindowManager.instance.getCurrent()returns by default and throwsArgumentErrorwhen skipped.dart run. Skipping Linux and Windows is covered only by the hook tests. I haven't tried a physical device.