You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cnativeapi: let apps skip building the native library on platforms where they don't use it #55
An app that uses window_manager only on desktop still builds and ships cnativeapi on Android and iOS, where nothing calls it. cnativeapi's build hook compiles and bundles the library for every target OS, and an app has no way to turn that off.
With window_manager 0.5.2 the native code was desktop-only plugin code, so mobile builds carried none of it.
#25 and #44 made the library smaller, which helps. This request is different: let an app leave the library out on platforms where it doesn't use it, saving the remaining size and the C++ compile time.
Suggestion
Skipping mobile for everyone would break apps that use nativeapi's Android and iOS features, so I'd suggest an opt-in setting through the hooks package's user_defines:
In bindings/dart/cnativeapi/hook/build.dart, after targetOS is read:
if (_skippedPlatforms(input).contains(targetOS.name)) {
return;
}
Set<String> _skippedPlatforms(BuildInput input) {
final value = input.userDefines['skip_platforms'];
if (value ==null) returnconst {};
final known = [
for (final os in [OS.android, OS.iOS, OS.linux, OS.macOS, OS.windows])
os.name,
];
if (value is!List||!value.every(known.contains)) {
throwFormatException(
'hooks.user_defines.cnativeapi.skip_platforms must be a list of ''${known.join(', ')}; got $value',
);
}
return value.cast<String>().toSet();
}
What I tried
I patched the published cnativeapi 0.6.2 this way and ran a small Dart program that imports nativeapi 0.6.2, on macOS arm64 with Dart 3.14.0:
skip_platforms
Result
not set
Library built, DisplayManager.instance.getAll() works
[macos], no nativeapi call
Starts normally, library not built
[macos], calling getAll()
ArgumentError: "Couldn't resolve native function … No asset with id 'package:cnativeapi/cnativeapi.dart' found"
[android, ios]
Same as not set on macOS
[beos]
Build hook fails
So a skipped platform only fails if the app calls into nativeapi there. I tested by skipping macOS. I haven't yet built or run an Android or iOS app with this, or measured the saving.
Would you accept this, and is this the shape you'd want? I'm happy to open a PR.
I've now tried this on Android and iOS, which I hadn't when I opened the issue.
The branch is skip-platforms, on top of 0b6135f: the hook change, a README section, and 15 test cases for the setting. They use testCodeBuildHook, and pass on Linux, macOS and Windows (run).
For the measurements I used a flutter create app with window_manager 0.7.1, the patched cnativeapi, and Flutter 3.50.0 (run):
Default
skip_platforms: [android, ios]
Android release APK (arm, arm64, x64)
46,985,920 bytes
43,086,233 bytes
libcnativeapi.so arm64-v8a
1,445,216 bytes
not in the APK
libcnativeapi.so armeabi-v7a
1,069,624 bytes
not in the APK
libcnativeapi.so x86_64
1,346,808 bytes
not in the APK
cnativeapi.framework binary, iOS release
781,136 bytes
not in the app
flutter build apk, two runs
5m17s, 5m08s
2m59s, 3m28s
flutter build ios, two runs
4m26s, 2m34s
0m46s, 1m18s
The build times are from shared GitHub runners, so they're only a rough guide.
Each app then drew its first frame and called WindowManager.instance.getCurrent(), in a release build on an Android emulator and a debug build on an iOS simulator:
Default
Skipped
Android
starts, the call returns
starts, the call throws ArgumentError
iOS
starts, the call returns
starts, the call throws ArgumentError
In the first run both iOS launch checks failed, with and without the setting, because my script only searched the console output. The second run checks for a file the app writes, and all four builds pass.
I can open a PR from that branch if you'd like this.
Activity
dbebawy commentedon Nov 23, 2026
I've now tried this on Android and iOS, which I hadn't when I opened the issue.
The branch is skip-platforms, on top of 0b6135f: the hook change, a README section, and 15 test cases for the setting. They use
testCodeBuildHook, and pass on Linux, macOS and Windows (run).For the measurements I used a
flutter createapp withwindow_manager0.7.1, the patchedcnativeapi, and Flutter 3.50.0 (run):skip_platforms: [android, ios]libcnativeapi.soarm64-v8alibcnativeapi.soarmeabi-v7alibcnativeapi.sox86_64cnativeapi.frameworkbinary, iOS releaseflutter build apk, two runsflutter build ios, two runsThe build times are from shared GitHub runners, so they're only a rough guide.
Each app then drew its first frame and called
WindowManager.instance.getCurrent(), in a release build on an Android emulator and a debug build on an iOS simulator:ArgumentErrorArgumentErrorIn the first run both iOS launch checks failed, with and without the setting, because my script only searched the console output. The second run checks for a file the app writes, and all four builds pass.
I can open a PR from that branch if you'd like this.