Facing some unknown issue some backend jvm internal error

Error message: "e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong bytecode generated"

In my case, I used runBlocking{} in one of MainViewModel.kt's methods.

The app was compiling successfully with runBlocking{} (which I shouldn't use anyway)) until I changed the name of a parameter in that method.

I replaced runBlocking{} with viewModelScope.launch {} in order to get ride of this error message.


I had the same error in kotlin 1.3.72 and the code that was causing it was a recursive suspend function contained in a suspend function:

suspend fun function1(){
  suspend fun internalFun(){
   // does something
   internalFun()  //<-- this was causing the problem
  }    
  internalFun()
}

I fixed by rearranging the code in such a way that i hadn't to call internalFun() inside itself. I don't know if the fact that they were suspend functions was relevant.


After struggling for a long time I found the solution, the code which causes the problem is this:

  if (investorType=="Institutional")
            {linSignUp
                if (firmName.isEmpty()) {

There is a problem in first if block which a linSignUp a reference of linear layout which accidentally placed here, which should not be here. So the View just here alone with no use, when I removed it, the build generated successfully.


This was one of the most frustrating errors to track down.

Here is the error I was getting:

java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Cause: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
.....

If your stack trace further on is related to views and strings, the main culprit for me was that the xml view id was too long.

This name caused the error: team_management_players_recycler_view_layout I reduced it to this: team_man_players_recycler_layout

BOOM ERROR WAS GONE!

Hope this helps someone else out!