Skip to content

Fix launch crash on iOS 16 and 17 by weak-linking UIKit - #302

Merged
mbernson merged 2 commits into
mainfrom
fix/ios-weak-link-uikit
Nov 24, 2026
Merged

mbernson merged 2 commits into
mainfrom
fix/ios-weak-link-uikit

Conversation

@mbernson

Copy link
Copy Markdown
Member

Problem

The app crashed on launch on iOS 16 and 17, before any of our code ran:

dyld: Symbol not found: _OBJC_CLASS_$_UITab

The native tab bar uses UITab, which only exists from iOS 18 (introduced in 76582f7). Unlike Swift and Clang, Kotlin/Native ignores API availability: it compiles newer APIs without an error and links every Objective-C class strongly, so dyld aborts when the class is missing. The deployment target is 16.2.

Fix

  • Link UIKit with -weak_framework UIKit in the iosApp target's OTHER_LDFLAGS (ProdDebug and ProdRelease). Classes missing on the running iOS version now resolve to nil instead of aborting the launch. The native tab bar is only created on iOS 26+, so UITab is never used where it is missing.
  • Keep UITab: replacing it with setViewControllers + UITabBarItem would bring back the empty third tab on the iPhone Duo side rail that 76582f7 fixed.
  • Document this in the README and AGENTS.md: newer iOS APIs must stay behind a runtime check, and the linker flag must stay.

Testing

  • otool -l shows UIKit loaded with LC_LOAD_WEAK_DYLIB, and nm -m shows _OBJC_CLASS_$_UITab as weak external.
  • iOS 17.5 simulator: the app launches and shows the Material tab bar.
  • iOS 27.2 simulator: the Liquid Glass tab bar shows and switching tabs works.
  • Not tested: iPhone Duo simulator, a real iOS 16 device, a release build.

🤖 Generated with Claude Code

mbernson and others added 2 commits November 24, 2026 12:57
Kotlin/Native ignores API availability and links every ObjC class
strongly, unlike Swift and Clang. The UITab reference used by the native
tab bar therefore made dyld abort on launch on iOS < 18 with "Symbol not
found: _OBJC_CLASS_$_UITab".

Linking UIKit with -weak_framework turns references to classes missing
from the running iOS into nil instead. The native tab bar is only created
on iOS 26+, so UITab is never used where it is missing. Any other newer
UIKit class must likewise stay behind a runtime version check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mbernson
mbernson requested a review from a team as a code owner November 24, 2026 12:29
Copilot AI balanced review requested due to automatic review settings November 24, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Simulator debug validation does not establish weak UITab linkage in a release binary or successful launch on the oldest supported iOS, leaving critical linker and runtime behavior unverified.

No open issues 🎉

What changed in this PR

This PR addresses the template’s iOS 16 and 17 launch crash caused by a strong reference to UITab, while preserving the existing native tab bar implementation.

Changes:

  • Weak-links UIKit in both ProdDebug and ProdRelease.
  • Documents why the linker flag must remain and why newer iOS APIs still require runtime availability checks.
File Description
README.MD Explains weak linking, availability guards, and oldest-supported-iOS testing.
iosApp/​iosApp.xcodeproj/​project.pbxproj Adds -weak_framework UIKit to both app build configurations.
AGENTS.MD Adds guidance to preserve weak linking and guard newer iOS APIs.

Review effort: Balanced

@mbernson
mbernson enabled auto-merge November 24, 2026 13:16

@kseniia-q42 kseniia-q42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for my on iOS 17!

@mbernson
mbernson merged commit b50a85b into main Nov 24, 2026
3 checks passed
@mbernson
mbernson deleted the fix/ios-weak-link-uikit branch November 24, 2026 13:42
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.

3 participants