Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Documentation #253

Closed Answered by Thaerith
natanfudge asked this question in Q&A
Discussion options

Is there any documentation for this project?

You must be logged in to vote

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

  1. place you google-services.json where official documentation required it (next to build.gradle.kts in you app module -- yes yes, even if your module is a KMP module, it doesn't matter).
  2. call with in you Application class:
import dev.gitlive.firebase.Firebase
... other imports

Replies: 4 comments

Comment options

It's super confusing. The library seems to be alive but there is absolutely no documentation and examples.

You must be logged in to vote
0 replies
Comment options

I'm trying to use it but no documentation

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

  1. place you google-services.json where official documentation required it (next to build.gradle.kts in you app module -- yes yes, even if your module is a KMP module, it doesn't matter).
  2. 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

You must be logged in to vote
0 replies
Answer selected by nbransby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /