← Back to Pull requests

[objective_c] Link Foundation in the native support library #3782

Closed
unknown closed this pull request without merging on Nov 06, 2026 01:56 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 18:22 UTC
Author

Description

The ObjC bindings load classes through their OBJC_CLASS_$_Foo symbols, resolved via the objective_c.dylib handle, and fall back to objc_getClass when that lookup throws (#3344). The native support library is linked with -undefined dynamic_lookup and no frameworks, so it only depends on libSystem:

$ otool -L objective_c.framework/objective_c
	@rpath/objective_c.framework/objective_c
	/usr/lib/libSystem.B.dylib

As a result dlsym can never find a built-in Foundation class through that handle, and the first use of every Foundation class in package:objective_c (NSArray, NSString, ...) throws an ArgumentError that getClass catches before falling back:

ArgumentError (Invalid argument(s): Couldn't resolve native function 'OBJC_CLASS_$_NSArray' in 'package:objective_c/objective_c.dylib' : Failed to lookup symbol 'OBJC_CLASS_$_NSArray': dlsym(0x90466c40, OBJC_CLASS_$_NSArray): symbol not found.

The result is still correct, but a debugger that breaks on all exceptions stops at app startup on any Flutter app that uses path_provider (via path_provider_foundation), with no way to skip just this exception.

This PR links the support library against Foundation, so these symbols resolve through the dylib's dependencies, to the same class pointers objc_getClass returns. The dylib's own classes (DOBJC*) still resolve as before, and the fallback is kept for other frameworks.

Related Issues

Follow-up to #3344 (which fixed #3338). There is no separate issue for this; happy to file one if preferred.

Testing

  • Added a test in test/internal_test.dart that resolves OBJC_CLASS_$_NSArray through package:objective_c/objective_c.dylib and compares it with getClass('NSArray'). It fails on main with the ArgumentError above and passes with this change.

  • Ran the macOS jobs of objective_c.yaml and ffigen.yml locally (macOS 27, Xcode 27.1, Flutter 3.47.9 / Dart 3.13.7):

  • - pkgs/objective_c: dart format --set-exit-if-changed, flutter analyze --fatal-infos, the snippet check and dart test (152 tests) pass.
    - example/command_line: dart run lib/main.dart works.
    - example/flutter_app: flutter build macos, flutter build ios --no-codesign and xcodebuild analyze (warnings as errors) succeed. otool -L on the bundled objective_c.framework now lists Foundation for both macOS slices and iOS.
    - pkgs/ffigen: dart test gives the same result with and without this change: 901 passed, 1 failed (verify_bindings_test for sdk_variable_test.dart, a bindings diff from the Xcode 27.1 SDK).

    Note: with the Xcode 27.1 SDK, test/generate_code_test.dart regenerates objective_c_bindings_generated.dart with a few new deprecated 27.0.0 annotations. That is unrelated to this change and not included.

    PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.

  • I've run dart tool/ci.dart --all locally and resolved all issues identified. (It doesn't cover pkgs/objective_c or pkgs/ffigen, so I also ran their workflow jobs, see Testing. Everything passes except 4 swift2objc integration tests, whose expected output differs with the local Xcode 27.1 Swift, and the swift2objc apitool missing-export check. This PR doesn't touch swift2objc, which doesn't depend on objective_c.)

  • All existing and new tests are passing. I added new tests to check the change I am making.

  • The PR is actually solving the issue.

  • I have updated CHANGELOG.md for the relevant packages.

  • I have updated the pubspec package version if necessary.
  • Diff: 474 lines (+355 / -119) across 5 files Reviewer: liamappelbe Review duration: 454m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 474 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.369
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3782"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.1% · Safe to merge
    18.1%