Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal compiler error when attempting to live edit multiplatform Compose code #4974

Closed
natanfudge opened this issue Jun 15, 2024 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@natanfudge
Copy link

Describe the bug
In a Compose MP project, while running on an Android device, live editing Android source set code is possible.
However, if you edit in a multiplatform (common) source set, an internal compiler error occurs.

Affected platforms
Android
Versions

  • Libraries:
    • Compose Multiplatform version:
      1.6.8
    • Compose Plugin version:
      1.6.11
  • Kotlin version:
    2.0.0
  • Device
    Android

To Reproduce
Steps to reproduce the behavior:

  1. Open any Compose multiplatform app that supports Android
  2. Make absolutely sure to have this in your android {} block in the app module's build.gradle (The example multiplatform Compose app doesn't do this):
    buildFeatures {
        compose = true
    }
  1. Launch Android app in an integrated emulator , use Android Studio to get the below error. The IntelliJ IDEA Android plugin simply says "Test sources not supported: filexyz.kt"
  2. Edit some Compose code in the commonMain source set
  3. Observe "Out Of Date" error:
    image
    Here it is as text:
Internal Error in App.kt. Internal Error During Code Gen. java.lang.ClassCastException: class org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments cannot be cast to class org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments (org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments and org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @787c3cc) at com.android.tools.idea.run.deployment.liveedit.CompileScopeImpl.backendCodeGen(CompileScope.kt:198) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compileKtFile$1$generationState$1.invoke(LiveEditCompiler.kt:165) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compileKtFile$1$generationState$1.invoke(LiveEditCompiler.kt:164) at com.android.tools.idea.run.deployment.liveedit.PerformanceTracker.record(PerformanceTracker.kt:28) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compileKtFile$1.invokeSuspend(LiveEditCompiler.kt:164) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compileKtFile$1.invoke(LiveEditCompiler.kt) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compileKtFile$1.invoke(LiveEditCompiler.kt) at com.android.tools.idea.run.deployment.liveedit.CompileScopeKt$runWithCompileLock$1.invokeSuspend(CompileScope.kt:248) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59) at kotlinx.coroutines.BuildersKt.runBlocking(Builders.kt:38) at kotlinx.coroutines.BuildersKt.runBlocking$default(Builders.kt:38) at com.android.tools.idea.run.deployment.liveedit.CompileScopeKt.runWithCompileLock(CompileScope.kt:246) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler.compileKtFile(LiveEditCompiler.kt:146) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler.access$compileKtFile(LiveEditCompiler.kt:40) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compile$compileCmd$1.invoke(LiveEditCompiler.kt:91) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compile$compileCmd$1.invoke(LiveEditCompiler.kt:79) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compile$1.invokeSuspend(LiveEditCompiler.kt:133) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compile$1.invoke(LiveEditCompiler.kt) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler$compile$1.invoke(LiveEditCompiler.kt) at com.intellij.openapi.application.impl.RwLockHolder.readAction(RwLockHolder.kt:271) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:845) at com.android.tools.idea.run.deployment.liveedit.LiveEditCompiler.compile(LiveEditCompiler.kt:126) at com.android.tools.idea.run.deployment.liveedit.LiveEditProjectMonitor.processChanges(LiveEditProjectMonitor.java:558) at com.android.tools.idea.run.deployment.liveedit.LiveEditProjectMonitor.doOnManualEditTrigger(LiveEditProjectMonitor.java:488) at com.android.tools.idea.run.deployment.liveedit.LiveEditProjectMonitor$4.invoke(LiveEditProjectMonitor.java:539) at com.android.tools.idea.run.deployment.liveedit.LiveEditProjectMonitor$4.invoke(LiveEditProjectMonitor.java:488) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840)

Expected behavior
Edited code is live edited into the Android device

Current workaround - recommended for any and all users of Jetbrains Compose, even if they don't even target Android:

  1. Add the following to the android { block in composeApp/build.gradle.kts:
android {
// ...
    buildFeatures {
        compose = true
    }
}
  1. Start writing in the Android source set only. In an existing app, cut & paste all your common code into androidMain.
  2. Test your app on an Android device (using Android Studio is preferred because it has the more up-to-date version of Live Edit that works much better) to take advantage of the Live Edit functionality, allowing instant GUI updates on code save, improving iteration speed significantly, especially for small changes.
  3. Be careful not to use any JVM-only APIs (java.* and most Kotlin reflection)
  4. When you are ready to publish your application, cut & paste all of your androidMain code into common, and resolve any platform specific errors (usually <1% of the work).
  5. Publish in all platforms
  6. For the next versions of your app, go back to step 2. A script could be used to speed up the cutting & pasting.
@natanfudge natanfudge added bug Something isn't working submitted labels Jun 15, 2024
@MatkovIvan
Copy link
Member

Supporting live edit for Multiplatform is tracked here - #2063, closing this as duplicate

For issues with Android Studio tooling, please use appropriate Google issue tracker.

@MatkovIvan MatkovIvan added duplicate This issue or pull request already exists and removed submitted labels Jun 18, 2024
@natanfudge
Copy link
Author

natanfudge commented Jun 18, 2024

@MatkovIvan can we get an official comment on #2036?
Woops, I meant #2063!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants