JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.95k stars 1.16k forks source link

Cannot execute app release with Proguard 7.4.2 #4391

Open mahozad opened 6 months ago

mahozad commented 6 months ago

Describe the bug When trying to execute runReleaseDistributable, app fails with this error:

Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    androidx/compose/runtime/SnapshotStateKt__DerivedStateKt.derivedStateOf$102ee4b4(Landroidx/compose/runtime/SnapshotMutationPolicy;Lkotlin/jvm/functions/Function0;)Landroidx/compose/runtime/DerivedSnapshotState; @24: areturn
  Reason:
    Type 'androidx/compose/runtime/State' (current frame, stack[0]) is not assignable to 'androidx/compose/runtime/DerivedSnapshotState' (from method signature)
  Current Frame:
    bci: @24
    flags: { }
    locals: { 'androidx/compose/runtime/SnapshotMutationPolicy', 'kotlin/jvm/functions/Function0' }
    stack: { 'androidx/compose/runtime/State' }
  Bytecode:
    0000000: 2a12 07b8 0017 2b12 06b8 0017 bb00 0859
    0000010: 2b2a b700 12c0 000c b0                 

    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:50241)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3236)
    at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:725)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:1071)
    at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:633)
    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:619)
    at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:219)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    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$4.run(Unknown Source)
    at java.desktop/java.awt.EventQueue$4.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)

Affected platforms Select one of the platforms below:

Versions

Expected behavior The app should run when executing runReleaseDistributable.

mahozad commented 6 months ago

For a workaround, I added this line to my rules.pro file:

-dontoptimize
EchoEllet commented 3 months ago

Do you use Material 3 or 2? Did you try with the default libraries included with the template without changing or including third-party libraries? Because Material 3 is not supported yet.

EchoEllet commented 3 months ago

Another workaround without disabling Proguard optimizations:

-keep class androidx.compose.runtime.** { *; }
-keep class kotlinx.coroutines.** { *; }

This will exclude Kotlinx coroutines from minimization, the bundle size will be 29.4 MB for the example desktop app on macOS Apple silicon JAR file, previously 28.3 MB with the runtime error

Tested with Compose 1.6.10, Proguard 7.5.0, and Kotlin 2.0.0 with a project created by kmp.jetbrains.com

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

mahozad commented 2 months ago

EchoEllet I'm using Material 2. Thanks for the tip.

EchoEllet commented 2 months ago

EchoEllet I'm using Material 2. Thanks for the tip.

I was able to use it with Proguard 7.5.0, Kotlin 2.0.0 and Material 3 with this workarorund