-
-
Notifications
You must be signed in to change notification settings - Fork 180
Documentation #253
-
Is there any documentation for this project?
Beta Was this translation helpful? Give feedback.
All reactions
All you need to know, you can use official documentation for general behaviour. There are no major differences, except that firebase kotlin makes life easier (in the asynchronous context) by using suspendable methods (so no more callbacks -- I'm from Android world, I used a bit firebase in JS/Typescript but I don't remember how it works).
The main difference is how you have to initialise the Firebase App.
For android
- place you
google-services.jsonwhere official documentation required it (next tobuild.gradle.ktsin you app module -- yes yes, even if your module is a KMP module, it doesn't matter). - call with in you Application class:
import dev.gitlive.firebase.Firebase ... other imports
Replies: 4 comments
-
It's super confusing. The library seems to be alive but there is absolutely no documentation and examples.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm trying to use it but no documentation
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi guys, I finished an article talking about the implementation in Android and iOS https://medium.com/@carlosgub/how-to-implement-firebase-firestore-in-kotlin-multiplatform-mobile-with-compose-multiplatform-32b66cdba9f7
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
All you need to know, you can use official documentation for general behaviour. There are no major differences, except that firebase kotlin makes life easier (in the asynchronous context) by using suspendable methods (so no more callbacks -- I'm from Android world, I used a bit firebase in JS/Typescript but I don't remember how it works).
The main difference is how you have to initialise the Firebase App.
For android
- place you
google-services.jsonwhere official documentation required it (next tobuild.gradle.ktsin you app module -- yes yes, even if your module is a KMP module, it doesn't matter). - call with in you Application class:
import dev.gitlive.firebase.Firebase ... other imports class AndroidApplication : Application() { override fun onCreate() { super.onCreate() Firebase.initialize(context = this) } }
note: this method has multiple overloads and you can see that context parameter is an Any?. but don't be scared, it is waiting for Android Context
For JS
For JS, it is slightly different. You must call the same function but you only need to pass a FirebaseOptions object. So, in your main function, simply call:
val firebaseConfig = FirebaseOptions( applicationId = "1:95***********", apiKey = "AIz***********", gaTrackingId = "G-***********", storageBucket = "***********.appspot.com", projectId = "***********-*****", gcmSenderId = "9***********2", authDomain = "***********-******.firebaseapp.com", ) fun main(){ Firebase.initialize(options = options) }
Going further
For my KMP project, I created a utility method I can call from any platform to set my emulators and so on...
class InitialiseFirebase { operator fun invoke(host: String, options: FirebaseOptions? = null, context: Any? = null) { if (options != null) { Firebase.initialize(options = options, context = context) } else { Firebase.initialize(context = context) } Firebase.auth.useEmulator(host, 9099) Firebase.firestore.useEmulator(host, 8080) } }
So I'm free to pass or the options if I'm in JS, or the android context... I didn't try for ios tho. For the WASM, it's going to be the same as JS, but I need to motivate myself to port firebase kotlin to WASM 😪
Oh yes, why did I choose to pass a required host parameter ? it's because when using android emulator, your "computer localhost" reachable through "10.0.0.2" and in JS, it's simply "localhost".
you can also imagine to run you firebase emulator in an other machine, so obviously the host is none of the two. (it isn't hard to configure 😉 )
Best regards,
Thaerith
Beta Was this translation helpful? Give feedback.
All reactions
-
🚀 1