Sort of strange one but was getting "Backend Internal error" error when using Jetpack Compose and turned out it was triggered by calling a function that takes a lambda from within a Coroutine.
It's pretty easy to reproduce....have narrowed it down to following steps:
Create new project using "Empty Compose Activity" template. Update to dev07 (had issue with previous versions as well) and also add following to build.gradle
composeOptions {
kotlinCompilerExtensionVersion = "0.1.0-dev07"
}
Add following to MyActivity.kt
fun someFun(success: (String) -> Unit) {
}
and then update onCreate to following:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launch {
someFun {
}
}
setContent {
MaterialTheme {
Greeting("Android")
}
}
}
Build project and then you see following error:
e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Element is unknownThe root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:42)
at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:35)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:114)
Note you also need to add following dependency to build.gradle
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"