I see that PR for JVM support (<https://github.com...
# realm
j
I see that PR for JVM support (https://github.com/realm/realm-kotlin/pull/448) has been merged....is there version available to try that out?
c
There is a
0.6.0-SNAPSHOT
on Maven Central. Haven’t tried actually consuming the jvm-artifacts through Maven Central yet and only works on MacOS, but you are of course welcome to give it a try https://github.com/realm/realm-kotlin#using-snapshots
👍 1
j
Getting following error when building with that....have tried with both Kotlin 1.5.30 and 1.5.31 and see same in both
Copy code
e: java.lang.AssertionError: Assertion failed
	at org.jetbrains.kotlin.ir.util.AdditionalIrUtilsKt.getPropertyGetter(AdditionalIrUtils.kt:241)
	at io.realm.compiler.RealmModelSyntheticPropertiesGeneration.addVariableProperty(RealmModelSyntheticPropertiesGeneration.kt:539)
	at io.realm.compiler.RealmModelSyntheticPropertiesGeneration.addProperties(RealmModelSyntheticPropertiesGeneration.kt:137)
	at io.realm.compiler.RealmModelLowering.lower(RealmModelLoweringExtension.kt:65)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitClass(Lower.kt:82)
hmm, noticed that README has following being used as dependency
Copy code
"io.realm.kotlin:library-base:${Versions.realm}"
whereas I had been using
Copy code
"io.realm.kotlin:library:${Versions.realm}"
I switched to that and getting different errors now
ok, fixed those (some api updates) and looking better now
and JVM support seems to be working nicely!
👍 1
n
Hi @John O'Reilly I've sent a PR to bump the dependency to
0.6.0
(instead of Snapshot). The released version contains a fix for JVM Windows platform.
👍 1
j
Just merged
👍 1
I haven't looked in to this yet in any detail but I noticed that I'm getting error running
Main.kt
(in
jvmMain
in common code). The Compose for Desktop app though is working. This is the error I'm seeing
Copy code
Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin io.realm.compiler.Registrar is not compatible with this version of compiler
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:618)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$ProjectEnvironment.registerExtensionsFromPlugins(KotlinCoreEnvironment.kt:130)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:170)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:431)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:226)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:152)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1500)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.AbstractMethodError: Receiver class io.realm.compiler.Registrar does not define or inherit an implementation of the resolved method 'abstract void registerProjectComponents(com.intellij.mock.MockProject, org.jetbrains.kotlin.config.CompilerConfiguration)' of interface org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar.
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerExtensionsFromPlugins$cli(KotlinCoreEnvironment.kt:610)
	... 28 more
could be some issue in my setup
n
which version of Studio/JVM are you running this against? it looks similar to the shadowing plugin issue https://youtrack.jetbrains.com/issue/KT-24946. did you try with
useIR = true
in the
common/build.gradle.kts
?
j
Using Android Studio Arctic Fox and Java 11
let me check that issue
n
I assume you're trying to run the
MainKt
from Studio (not from command line by specifying the classpath etc.) ...
j
correct
if you have chance can you try and run it there
👍 1
wonder if it could be related to this....
I have live coding talk in a few days so probably won't change that until that's over 🙂
n
😄 sure. Can you please share your
Run/Debug
configuration? I have the following which isn't launching anything
Note: I fixed the package name of
MainKt
to
dev.johnoreilly.common
j
message has been deleted
(updated package)
kicking off from here
This was something I had a while back before I started using Realm in this project so could be something else has changed as well
I tried various options btw under "JRE"
n
strange ... clicking on studio doesn't run anything, I'll see if I can reproduce on another machine
j
hmm, I did fresh clone of project (+ fixed that package name) and now getting a bit further.....getting error now re.
Copy code
Module with the Main dispatcher is missing.
n
do you have the complete stack trace?
j
Copy code
Exception in thread "main" java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
	at kotlinx.coroutines.internal.MainDispatchersKt.throwMissingMainDispatcherException(MainDispatchers.kt:79)
	at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MainDispatchers.kt:110)
	at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:94)
	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:319)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.startCoroutineImpl(Builders.common.kt:192)
	at kotlinx.coroutines.BuildersKt.startCoroutineImpl(Unknown Source)
	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:134)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
	at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
	at dev.johnoreilly.common.data.repository.FantasyPremierLeagueRepository.<init>(FantasyPremierLeagueRepository.kt:71)
	at dev.johnoreilly.common.di.KoinKt$commonModule$1$6.invoke(Koin.kt:38)
	at dev.johnoreilly.common.di.KoinKt$commonModule$1$6.invoke(Koin.kt:38)
	at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
	at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
	at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:53)
	at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:51)
	at org.koin.mp.KoinPlatformTools.synchronized(PlatformToolsJVM.kt:20)
	at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:51)
	at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:103)
	at org.koin.core.scope.Scope.resolveValue(Scope.kt:223)
	at org.koin.core.scope.Scope.resolveInstance(Scope.kt:211)
	at org.koin.core.scope.Scope.get(Scope.kt:193)
	at dev.johnoreilly.common.MainKt$main$1.invokeSuspend(Main.kt:44)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:87)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:61)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:40)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at dev.johnoreilly.common.MainKt.main(Main.kt:11)
	at dev.johnoreilly.common.MainKt.main(Main.kt)
that
MainScope
usage might have been added to repository class since last time that code had run before
it must be setup for Compose for Desktop but probably not then if just running main function like this....
I can't remember history of why it was used in
init
block of
FantasyPremierLeagueRepository
like that....
I'll take a closer look later
👍 1
as a hack I tried following and seemed to work
Copy code
val dispatcher = Executors
        .newSingleThreadExecutor()
        .asCoroutineDispatcher()

    Dispatchers.setMain(dispatcher)
had to add
kotlinx-coroutines-test
to get
setMain
(also had to update ktor jvm driver....not fully sure why but was using that one in PeopleInSpace as well for some reason)
also debatable whether using repository makes sense for main function like this if we're hitting endpoints anyway (at least in terms of having the persistence functionality)
guess it depends on how it's going to be used
n
BTW I added a new Console sample to double check the behaviour when using a classic Java project (not multiplatform) it seems to work both from the Intellij IDEA and as a standalone JAR https://github.com/realm/realm-kotlin-samples/tree/main/JVMConsole
j
Cool, will take a look