KMM Firebase Authentication API demo using GitLiveApp/firebase-kotlin-sdk
Note: This sample project demonstrates how to link KMM apps to the Firebase API. I made this example because I had a lot of trouble getting it to function.
1.Followed this document to make the project:
- Added Fiebase dependenceis on shared/commonMain and implemented FirebaseAuthentication class
- Implemented androidApp --> This compiles and launches fine. It throws error because FirebaseApp is not initialized. but for this demo, the actual FirebaseApi is functioning on Android
- iOS throws this error --> ld: framework not found FirebaseAuth
- Added "isStatic = true" on the Shared gradle. This post helped me with this [GitLiveApp/firebase-kotlin-sdk#288 (comment)]
- ios Now throws the ff Error:
Could not find or use auto-linked framework 'FirebaseAuth'
Could not find or use auto-linked framework 'GoogleUtilities'
Could not find or use auto-linked framework 'FirebaseCore'
Could not find or use auto-linked framework 'GTMSessionFetcher'
Could not find or use auto-linked framework 'FirebaseInstallations'
Could not find or use auto-linked framework 'GoogleAppMeasurement'
Could not find or use auto-linked framework 'GoogleAppMeasurementIdentitySupport'
Could not find or use auto-linked framework 'FirebaseCoreDiagnostics'
Could not find or use auto-linked framework 'GoogleDataTransport'
Could not find or use auto-linked framework 'nanopb'
Could not find or use auto-linked framework 'FirebaseAnalytics'
Could not find or use auto-linked framework 'PromisesObjC'
Undefined symbol: _FIRAuthErrorDomain
Undefined symbol: _OBJC_CLASS_$_FIRUser
Undefined symbol: _OBJC_CLASS_$_FIRMultiFactorSession
Undefined symbol: _OBJC_CLASS_$_FIRPhoneAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRAuthDataResult
Undefined symbol: _OBJC_CLASS_$_FIRGoogleAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRMultiFactorInfo
Undefined symbol: _OBJC_CLASS_$_FIREmailAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRGitHubAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRFacebookAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRActionCodeSettings
Undefined symbol: _OBJC_CLASS_$_FIRTwitterAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIRAuth
Undefined symbol: _OBJC_CLASS_$_FIROAuthProvider
Undefined symbol: _OBJC_CLASS_$_FIROptions
Undefined symbol: _OBJC_CLASS_$_FIRActionCodeInfo
Undefined symbol: _OBJC_CLASS_$_FIRAuthTokenResult
Undefined symbol: _OBJC_CLASS_$_FIRApp
- This tutorial lists the ff to link iOS to the shared framework:
1. Add the ff script to buildphas:
cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode
2. Add the following path to `Framework search`:
$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)
3. Add the ff to Other Linker Flags`:
$(inherited) -framework shared
I confirmed the above steps are configured. I'ts configured since I created KMM project from scratched
- Adding the Firebased sdk to ios Resolved the above issues
- Now I get the ff warnings but app launches and everything works:
(x86_64) could not find object file symbol for symbol _kfun:dev.gitlive.firebase.Firebase#<init>(){}
(x86_64) could not find object file symbol for symbol _kfun:dev.gitlive.firebase.FirebaseException#<init>(kotlin.String){}
(x86_64) could not find object file symbol for symbol __Konan_init_dev.gitlive:firebase-app
(x86_64) could not find object file symbol for symbol _kifacetable:dev.gitlive.firebase.Firebase
(x86_64) could not find object file symbol for symbol _krefs:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol _kifacetable:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol _kextoff:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol _kexttype:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol ___unnamed_36
(x86_64) could not find object file symbol for symbol ___unnamed_37
(x86_64) could not find object file symbol for symbol ___unnamed_38
(x86_64) could not find object file symbol for symbol ___unnamed_39
(x86_64) could not find object file symbol for symbol ___unnamed_40
(x86_64) could not find object file symbol for symbol _kclass:dev.gitlive.firebase.Firebase
(x86_64) could not find object file symbol for symbol _kclass:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol _kextname:dev.gitlive.firebase.FirebaseException
(x86_64) could not find object file symbol for symbol _kobjref:dev.gitlive.firebase.Firebase
(x86_64) could not find object file symbol for symbol _ktypew:dev.gitlive.firebase.Firebase
(x86_64) could not find object file symbol for symbol _ktypew:dev.gitlive.firebase.FirebaseException
TODO: Make sure to add GoogleService-Info.plist to your project