Unresolved reference 'FirebasePlatform'.
Closed this issue · 4 comments
I have a Kotlin Multiplatform project. The file tree loks like this:
/shared
/androidApp
/desktopApp
While the shared depencenies has that:
kotlin {
jvm() // Target for Desktop
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation("org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha02")
implementation("dev.gitlive:firebase-database:1.13.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
}
}
}
}
My androidApp has a single dependency to the shared
project, and the build.gradle.kts uses the kotlin("android")
plugin.
Inside my shared project I have the following Application.init
function:
object Application {
fun init() {
FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() {
val storage = mutableMapOf<String, String>()
override fun store(key: String, value: String) = storage.set(key, value)
override fun retrieve(key: String) = storage[key]
override fun clear(key: String) {
storage.remove(key)
}
override fun log(msg: String) = println(msg)
})
val options = FirebaseOptions.Builder()
.setProjectId("someId")
.setApplicationId("anotherId")
.setApiKey("apiKey")
.setDatabaseUrl("someUrl")
.build()
Firebase.initialize(Application(), options)
}
}
My androidApp tries to call this in their own android.app.Application().
However, when I try to compile the app (./gradlew assembleDebug
) I get these:
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:6:28 Unresolved reference 'FirebasePlatform'.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:11:9 Unresolved reference 'FirebasePlatform'.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:11:62 Unresolved reference 'FirebasePlatform'.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:13:13 'store' overrides nothing.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:14:13 'retrieve' overrides nothing.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:15:13 'clear' overrides nothing.
e: file:///somePath/shared/src/commonMain/kotlin/com/package/Application.kt:19:13 'log' overrides nothing.
Does anyone know why this happen? 🤔
Do I something wrong?
Btw, my desktopApp
works fine without any issues.
There, my main.kt
looks like this:
fun main() = application {
Application.init()
Window(onCloseRequest = ::exitApplication) {
App()
}
}
Everything compiles and runs correctly.
But for the Android target something is missing for whatever reasons.
FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() { val storage = mutableMapOf<String, String>() override fun store(key: String, value: String) = storage.set(key, value) override fun retrieve(key: String) = storage[key] override fun clear(key: String) { storage.remove(key) } override fun log(msg: String) = println(msg) })
this part should only be in desktopApp
Firebase.initialize(Application(), options)
also this part needs to pass the android context on android instead of Application()
, or you can put all of this in desktopApp and use the Firebase configuration file on Android
Thank you for the quick response!
That makes sense. I will give it a try and report back if it works 👌
Nice, it works.
Thanks again!
I guess it make sense to adjust the docs in the java-sdk repo 😉