Files
Andrew Heard acbf36caee fix(ai): replace Mutex to fix crash on iOS < 18 (#17024)
GeminiAPIClient's SessionDelegate and TaskDelegate stored
Synchronization.Mutex properties. Swift classes are listed in the
Objective-C class list regardless of @available, so enumerating the
classes (e.g., with objc_copyClassList, as Realm does) or looking one
up by name realized them on iOS 17 and earlier. TaskDelegate's
Mutex<ResponseState> required runtime layout, so realizing it called
the weakly linked Mutex metadata accessor, which is NULL before iOS 18,
and the app crashed. GeminiLanguageModel is only built with Swift 6.4+,
so this affected apps built with Xcode 27 even if they didn't use it.

- Replace Mutex with LockedValue, an NSLock-based class that mirrors
  the init and withLock signatures of Mutex. Add a TODO to switch back
  once the minimum deployment targets always include Mutex, and link
  the upstream Swift runtime issues (swiftlang/swift#61215 and
  swiftlang/swift#72657).
- Add a FirebaseAILogicUnit test that calls objc_copyClassList. No CI
  runner has a simulator old enough to catch this crash, so the fix
  was verified locally on a tvOS 17.5 simulator, before and after.

Fixes #17012
2026-11-09 16:12:20 -05:00
..

See the Firebase AI SDK README for required setup instructions.