https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

Abdul Basit

11/30/2023, 4:28 PM
I am having a destop app, and i am using Centrifugal for socket communication. It works fine in debug version and I am able to receive messages. but in release distribution, i am getting
3502
(connection stale ) and the connection disconnects. any idea what is happening ?
a

Alexander Maryanovsky

11/30/2023, 4:45 PM
What makes you think Compose is to blame?
a

Abdul Basit

11/30/2023, 4:45 PM
Not saying compose is to blame. Just wondering what could be the issue.
As this is the desktop channel, so wanted to know if someone faced same issue.
k

Kirill Grouchnikov

11/30/2023, 5:19 PM
Make the simplest
main()
function with no compose bits, build it in release mode, and file a bug in https://github.com/centrifugal/centrifuge-java/issues
m

Michael Paus

11/30/2023, 5:43 PM
As @Abdul Basit is explicitly mentioning a behavioural difference between the debug version and the release distribution, it is quite likely that the problem is due to something missing after the ProGuard or packaging phase. I doubt that creating an issue for centrifugal would solve this. At first I would switch off ProGuard and see whether it makes a difference.
👆 1
a

Abdul Basit

12/01/2023, 4:52 AM
I tried to disable the proguard
Copy code
buildTypes.release {
    proguard {
        obfuscate.set(false)
        configurationFiles.from("<http://compose-desktop.pro|compose-desktop.pro>")
    }
}
but still having same issue. Let me try to run this with no compose.
I tried without Compose and the assembled and it is working fine.
m

Michael Paus

12/01/2023, 8:36 AM
There are more ProGuard related options than the one you have used.
Copy code
buildTypes.release {
    proguard {
        version.set("7.4.0")
        isEnabled.set(false)
        optimize.set(false)
        obfuscate.set(false)
        configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
    }
}
You have just disabled the obfuscation but not ProGuard completely. I’d try with my snippet above first and if it works enable ProGuard via the isEnabled parameter. I normally leave the others disabled because for desktop they don’t seem to have a significant effect but just make the build less predictable.
a

Abdul Basit

12/01/2023, 2:17 PM
I set the above options but still same 😢 But i believe the issue is due to proguard.
m

Michael Paus

12/01/2023, 3:51 PM
If you have the same issues when you have switched off ProGuard, then it is difficult to still blame ProGuard for the problems, isn’t it? In this case I would try to find out whether something is missing in the packaging. Have you specified all the modules that you need?
a

Abdul Basit

12/01/2023, 3:53 PM
Hmm, yeah it also makes sense. The code is simple. Just open a socket connection and listen to the messages. So just the dependency and nothing else. I will also try with Ktor.
Copy code
fun App() {

    val centrifuge = Client(
        SOCKET_CONNECTION_LINK,
        Options(),
        object : EventListener() {
            override fun onConnected(client: io.github.centrifugal.centrifuge.Client?, event: ConnectedEvent?) {
                super.onConnected(client, event)
                println("Connected")
            }

            override fun onDisconnected(client: io.github.centrifugal.centrifuge.Client?, event: DisconnectedEvent?) {
                super.onDisconnected(client, event)
                println("Disconnected")
            }

            override fun onError(client: Client?, event: ErrorEvent?) {
                super.onError(client, event)
                println("Error ${event?.error?.message}")
            }
        }
    )


    // Subscribe to a channel and handle incoming data
    val channel = socketChannel
    val subscription = centrifuge.newSubscription(channel,
        object : SubscriptionEventListener() {
            override fun onPublication(sub: Subscription, event: PublicationEvent) {
                println("Published message ${String(event.data, StandardCharsets.UTF_8)}")
            }

            override fun onError(sub: Subscription?, event: SubscriptionErrorEvent?) {
                super.onError(sub, event)
                println("Error ${event?.error?.message}")
            }
        }
    )
    try {
        centrifuge.connect()
        subscription.subscribe()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}
Also, it works fine with Android
m

Michael Paus

12/05/2023, 3:12 PM
If you have disabled ProGuard and it still does not work the next step is to follow these instruction here: https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Native_distributions_and_local_execution#configuring-included-jdk-modules Especially try setting
includeAllModules = true
in the
nativeDistributions
section.
❤️ 1
🙇 1
a

Abdul Basit

12/05/2023, 3:17 PM
it worked with
includeAllModules = true
Thank you so much @Michael Paus 🙇
m

Michael Paus

12/05/2023, 3:18 PM
Now you can try to optimize this with
suggestModules
and if that is not sufficient try to find the necessary modules manually.
a

Abdul Basit

12/05/2023, 3:25 PM
Sure, will check this out.
2 Views