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.88k stars 1.15k forks source link

The documentation of obfuscation should mention Proguard `-keep` rules #4288

Open dkhalanskyjb opened 7 months ago

dkhalanskyjb commented 7 months ago

Describe the bug

https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Native_distributions_and_local_execution#minification--obfuscation provides inaccurate instructions. When followed, they will lead to a project that doesn't work. See https://github.com/JetBrains/compose-multiplatform/issues/3047 and https://github.com/Kotlin/kotlinx.coroutines/issues/4025.

Affected platforms

Versions

Current master as of writing.

To Reproduce

  1. Follow the steps in https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Native_distributions_and_local_execution#minification--obfuscation
  2. Try running your project.
  3. Observe the exception "Module with the Main dispatcher is missing."

Expected behavior The project works.

Screenshots Not applicable.

Additional context The rule that seems to do the trick is:

-keep class * implements kotlinx.coroutines.internal.MainDispatcherFactory

Anecdotally, this seems to be sufficient.

If some other issues arise with Proguard + Coroutines, here's the full list of rules that were needed for Proguard at some point https://github.com/Kotlin/kotlinx.coroutines/blob/13f27f729547e5c22d17d5b5de3582d450b037b4/kotlinx-coroutines-core/jvm/resources/META-INF/com.android.tools/proguard/coroutines.pro . A lot of this is probably only needed for older Proguard versions, though.

okushnikov commented 1 month ago

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