Skip to content

fix(macos): link ServiceManagement weakly for macOS 12 - #87

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

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

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.

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#20

## 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 macOS 12 fix and your Monterey verification!

Merged as 472b2ad, and the workspace core pointer has been updated. Together with nativeapi #20, this is now shipped in Dart release v0.5.7, covering cnativeapi, nativeapi, and nativeapi_flutter. All three packages were published successfully and their pub.dev archives were verified.

Our CMake and Dart native-asset builds targeting macOS 12 also confirmed weak ServiceManagement load commands and weak SMAppService imports.

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