GitLiveApp / firebase-java-sdk

A pure java port of the Firebase Android SDK
Apache License 2.0
18 stars 6 forks source link

On generated MSI file getting error "failed to launch JVM" error" But in emulator every thing is OK. #21

Open MrJabborbek opened 3 months ago

MrJabborbek commented 3 months ago

I am initializing Firebase in desktop side like this, if i commented firebsase initializationsnot getting error, so error is in initialization:

import android.app.Application import androidx.compose.ui.window.Window import androidx.compose.ui.window.application import com.google.firebase.FirebasePlatform import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseOptions import dev.gitlive.firebase.initialize

fun main() = application { FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() {

    val storage = mutableMapOf<String, String>()
    override fun clear(key: String) {
        storage.remove(key)
    }

    override fun log(msg: String) = println(msg)

    override fun retrieve(key: String) = storage[key]

    override fun store(key: String, value: String) = storage.set(key, value)

})

val options = FirebaseOptions(
    projectId = "some_id",
    applicationId = "app_id_here",
    apiKey = "api_key_here",
)

Firebase.initialize(Application(), options)

Window(
    onCloseRequest = ::exitApplication,
    title = "KotlinProject",
) {
    App()
}

}

nbransby commented 3 months ago

Are you able to get more information about the error such as a full stack trace?

JacobCube commented 2 months ago

Perhaps related to this, whenever I run ./gradlew runReleaseDistributable I get an error Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory.

Full stacktrace:

Task :composeApp:runReleaseDistributable

Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory
at android.os.SystemClock.elapsedRealtime(SystemClock.java:7)
at com.google.firebase.StartupTime.now(StartupTime.java:54)
at com.google.firebase.provider.FirebaseInitProvider.<clinit>(FirebaseInitProvider.java:38)
at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:412)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:296)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
at com.google.firebase.FirebaseKt.initialize(Firebase.kt:49)
at MainKt.initializeFirebase(main.kt:115)
at MainKt.initializeFirebase$default(main.kt:95)
at ComposableSingletons$MainKt$lambda-2$1.invoke(main.kt:43)
at ComposableSingletons$MainKt$lambda-2$1.invoke(main.kt:38)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:117)
at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:233)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:232)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:223)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:221)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:33)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3595)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3522)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:743)
at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:1114)
at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:649)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:635)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:221)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: java.lang.management.ManagementFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 49 more

Seems to be this method

public static long elapsedRealtime() {
        return ManagementFactory.getRuntimeMXBean().getUptime();
    }
nbransby commented 1 day ago

Ah yes that method is not available on all runtimes but firebase depends on it, would be great to find another way to get the time since last reboot although I suspect replacing this with simply the time since the application started would suffice