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

Mark Alvaro

01/25/2023, 5:12 PM
In trying to use Compose Desktop 1.2, I'm running into ProGuard issues with it minifying things that need to be accessed reflectively (specifically using HiveMQ MQTT client, which relies on jctools). I'd prefer to just disable it for now, because I'm just building a toy app and don't want to spend time learning and configuring ProGuard. I tried just downgrading to Compose 1.1, but now am getting an error about the IR compiler:
Copy code
Unable to find method ''void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)''
'void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)'
Does anyone know how to just disable ProGuard? Most stackoverflow posts unfortunately don't cover it with modern build.gradle.kts syntax.
And for what it’s worth, I’ve tried this:
Copy code
compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "myapp"
            packageVersion = "1.0.0"
        }
        buildTypes.release.proguard {
            configurationFiles.from("<http://rules.pro|rules.pro>")
        }
    }
}
with a rules.pro file at the root level of my project (same directory as build.gradle.kts) with the following contents:
Copy code
-keepclassmembernames class io.netty.** { *; }
-keepclassmembers class org.jctools.** { *; }
Where I was trying to follow the directions on the JetBrains Blog using the suggestions from this post for configuration. But ultimately it’s still failing at runtime as it can’t find the class or do some logic in that class’s initialization block.
Also have tried setting
isEnabled.set(false)
in the proguard block above, but that doesn’t seem to do it either.
It’s definitely frustrating to introduce something like ProGuard and not document well how to opt out or configure it specifically when using Compose Desktop, given most Android examples I see on Stack Overflow don’t seem to work for Compose Desktop.
d

Dima Avdeev

01/25/2023, 7:21 PM
@alexey.tsvetkov Can you please help with answer?
m

Mark Alvaro

01/26/2023, 1:27 PM
Tried downgrading to Compose 1.1.0, which ultimately I got to work with Kotlin 1.6.10. Unfortunately still running into the same issue of class not found/initialization errors. Any other ideas for why packaging as dmg instead of just running in IDEA fails bc of class not found stuff with classes that use reflection.
a

alexey.tsvetkov

01/26/2023, 1:38 PM
@Mark Alvaro 1. ProGuard support is opt-in. Basically we introduced an addition “release” toolchain. So if you don’t use “release” tasks (e.g.
createReleaseDistributable
is the “release” version of
createDistributable
), then ProGuard does not run. This is documented https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#minification--obfuscation 2. Even before ProGuard support we had support, which minifies JDK image through
jlink
. This only applies to the JDK standard library. It was enabled by default to improve the default image size out-of-the-box (which was probably not the best decision). However, at the time we did not find the way to reliable automate selection of modules, so a set of included modules is either has to be adjusted manually or all modules should be included. This part is documented https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#configuring-included-jdk-modules
m

Mark Alvaro

01/26/2023, 1:47 PM
Thank you so much for the detailed response. Super helpful and hopefully will have me on my way!
a

alexey.tsvetkov

01/26/2023, 1:52 PM
@Mark Alvaro feel free to mention me in this thread or write directly using DM in case if the docs don’t help. Also, I hope we will be able to simplify & streamline the minification process in the coming months, but sadly it won’t happen overnight
m

Mark Alvaro

01/26/2023, 1:53 PM
Just got it working!
Had already gone to Compose 1.1.0, and the includeAllModules flag in the docs you linked to fixed my problems.
37 Views