An iOS and macOS app with a SwiftUI frontend and a Kotlin Multiplatform library that talks to Firebase.
The Kotlin library gets the Firebase Apple SDK through the Kotlin Gradle Plugin's SwiftPM import
(swiftPMDependencies {}), and both the library and the SwiftUI previews can run against a mock instead of Firebase.
SwiftPM import is the recommended way to add Firebase to a Kotlin Multiplatform project.
Note
The CocoaPods integration is deprecated. Firebase stops publishing new versions to CocoaPods in October 2026, and
Firebase 12 is the last major version there
(Firebase announcement). The earlier CocoaPods version
of this sample is kept, unmaintained, on the cocoapods branch.
The app supports email/password sign-up, sign-in and sign-out, stores user profiles in Firestore, and logs events to Firebase Analytics.
kotlin-library is the KMP module with the Firebase logic.
build.gradle.ktslists the Firebase SwiftPM products that Kotlin code uses directly. You don't need to list transitive modules such asFirebaseCoreorFirebaseInstallations; the plugin imports them automatically.FirebaseKMPis the API the Swift app calls.FirebaseKMPImplimplements it with Firebase, andMockFirebaseKMPImplimplementsMockFirebaseKMPfor tests and previews.- The library targets iOS and macOS, so most code lives in
appleMain.appleMain/.../sampleshas one sample per Firebase product: App Check, A/B Testing, Crashlytics, Realtime Database, Cloud Functions, Installations, Remote Config, Storage, and Firebase AI Logic. App Distribution, In-App Messaging and Performance exist only for iOS, so their products are limited to iOS inbuild.gradle.ktsand their samples are iniosMain. FirebaseAIBridgeis a local Swift package that wraps the Swift-onlyFirebaseAILogicSDK in@objcclasses. SwiftPM import uses cinterop, which only sees Objective-C compatible declarations, so a wrapper like this is how Kotlin code can call a Swift-only library. The module adds it withlocalSwiftPackage(...).
appleApp is the SwiftUI app. One Xcode target builds it for iPhone and iPad (iOS 18) and for Mac (macOS 15).
The bundle ID ends in .iosApp because it has to match the app registered in GoogleService-Info.plist.
FirebaseService.swiftis an@Observablemodel that turns the callback-based Kotlin API intoasyncfunctions.Views/has the login and registration screen (AuthView) and the profile screen (ProfileView).KotlinMultiplatformLinkedPackageis generated by the Kotlin Gradle Plugin, and the Xcode project references it as a local package to link the SwiftPM dependencies into the app. Commit it, but don't edit it by hand.
- Install Xcode 26.2 or later (Firebase 13 requires it) and IntelliJ IDEA or Android Studio. You need a Mac.
- Create a Firebase project, register an iOS app, and put its
GoogleService-Info.plistinappleApp/appleApp. Enable Email/Password sign-in and set up Firestore security rules. - Open
appleApp/appleApp.xcodeprojin Xcode, pick an iOS or macOS destination, and run the app. The Compile Kotlin Framework build phase builds the Kotlin library with./gradlew :kotlin-library:embedAndSignAppleFrameworkForXcode. - To sign in on a Mac, select your development team and add the Keychain Sharing capability to the
appleApptarget. Firebase Auth on macOS keeps the signed-in user in the keychain.
After you edit swiftPMDependencies {} in kotlin-library/build.gradle.kts, the next Xcode build regenerates
KotlinMultiplatformLinkedPackage and fails with "Synthetic linkage package files changed during the build" and
"Please go to File -> Package -> Resolve Package Versions in Xcode". Resolve the packages or build again, then commit
the regenerated files along with .swiftpm-locks/default/swiftImport/Package.resolved, which pins the package versions
used on the Kotlin side.