Skip to content

fix(macos): link ServiceManagement weakly so the library loads on macOS 12 - #20

Merged
lijy91 merged 1 commit into
libnativeapi:mainfrom
yx-wh:yx-wh-macos12
Nov 2, 2026
Merged

lijy91 merged 1 commit into
libnativeapi:mainfrom
yx-wh:yx-wh-macos12

Conversation

@yx-wh

@yx-wh yx-wh commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On macOS 12 the built cnativeapi library fails to load:

dlopen(cnativeapi.framework/cnativeapi, 0x0001): Symbol not found: (_OBJC_CLASS_$_SMAppService)
  Referenced from: cnativeapi.framework/Versions/A/cnativeapi
  Expected in: /System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement

Every FFI entry point then throws, even for unrelated APIs such as the tray
icon or the shortcut manager, because the library never loads.

Root cause

ServiceManagement is linked normally, and SMAppService only exists on
macOS 13+. The build uses the current macOS SDK, so
__has_include(<ServiceManagement/SMAppService.h>) is always true and
_OBJC_CLASS_$_SMAppService is emitted as a required (non-weak) symbol.

The @available(macOS 13.0, *) guards in launch_at_login_macos.mm only
prevent execution; they do not remove the compile-time symbol reference.

Fix

Link the framework weakly so the library loads on macOS 12, where the
existing availability checks then keep Enable() / Disable() /
IsEnabled() returning false. Behaviour on macOS 13+ is unchanged.

The CMake path needs the same change; that file lives in nativeapi-core,
so a companion PR is open there: nativeapi-core/pull/87.

Verification

Built and run on macOS 12 (Monterey, x86_64) with
MACOSX_DEPLOYMENT_TARGET = 12.0:

otool -l cnativeapi | grep -A2 LC_LOAD
  cmd LC_LOAD_WEAK_DYLIB
  name .../ServiceManagement.framework/Versions/A/ServiceManagement

nm -m cnativeapi | grep SMAppService
  (undefined) weak external

The app starts normally and tray/shortcut APIs work. Launch-at-login reports
"unsupported" on macOS 12, which is expected.

Companion to libnativeapi/nativeapi-core#87

…OS 12

## Problem

On macOS 12 the built `cnativeapi` library fails to load:

lijy91 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks @yx-wh for the fix and for verifying it on macOS 12!

This PR and nativeapi-core #87 have been merged. The fix is now published in v0.5.7: cnativeapi 0.5.7, nativeapi 0.5.7, and nativeapi_flutter 0.5.7.

We also verified the macOS 12-targeted CMake and Dart native-asset builds have weak ServiceManagement load commands and weak SMAppService imports. The release workflow passed, and we checked that the published cnativeapi archive includes both linking changes.

yx-wh added a commit to yx-wh/Ciyue that referenced this pull request Nov 2, 2026
… link

cnativeapi 0.5.7 links ServiceManagement weakly upstream (libnativeapi/nativeapi#20 and nativeapi-core#87), so patching the package after pub get is no longer needed. Bump the lock file and drop the CI step and the script.
yx-wh added a commit to yx-wh/Ciyue that referenced this pull request Nov 2, 2026
cnativeapi 0.5.7 links ServiceManagement weakly upstream (libnativeapi/nativeapi#20, nativeapi-core#87), so the app no longer needs a post-pub-get patch to load on macOS 12. Bump the lock file; the earlier weak-link patch and its CI step are dropped because they are now redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants