Reputation: 2417
I have a big project and I decided to add jetpack compose to it. First, I prepared a standalone project with some @Composable
components, and everything was working. Then, after adding sources and preper dependencies to my project during compilation I started receiving this error:
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: C:/Users/.../CatalogScreen.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:239)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException$default(CodegenUtil.kt:235)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invokeSequential(performByIrFile.kt:68)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:55)
at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(performByIrFile.kt:41)
...
Caused by: java.lang.RuntimeException: Exception while generating code for:
FUN name:CatalogScreen visibility:public modality:FINAL <> () returnType:kotlin.Unit
annotations:
Composable
BLOCK_BODY
VAR PROPERTY_DELEGATE name:currentTab$delegate type:androidx.compose.runtime.MutableState<kotlin.Int> [val]
CALL 'public final fun remember <T> (calculation: @[DisallowComposableCalls] kotlin.Function0<T of androidx.compose.runtime.ComposablesKt.remember>): T of androidx.compose.runtime.ComposablesKt.remember [inline] declared in androidx.compose.runtime.ComposablesKt' type=androidx.compose.runtime.MutableState<kotlin.Int> origin=null
<T>: androidx.compose.runtime.MutableState<kotlin.Int>
calculation: BLOCK type=kotlin.Function0<androidx.compose.runtime.MutableState<kotlin.Int>> origin=LAMBDA
COMPOSITE type=kotlin.Unit origin=null
FUNCTION_REFERENCE 'private final fun CatalogScreen$lambda-0 (): androidx.compose.runtime.MutableState<kotlin.Int> declared in ...CatalogScreenKt' type=kotlin.Function0<androidx.compose.runtime.MutableState<kotlin.Int>> origin=LAMBDA reflectionTarget=null
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate$default(FunctionCodegen.kt:43)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethodNode(ClassCodegen.kt:349)
...
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'remember' into
@androidx.compose.runtime.Composable public fun CatalogScreen(): kotlin.Unit defined in ...catalog
<no source>
Cause: Not generated
File is unknown
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.getCompiledMethodNodeInner(InlineCodegen.kt:578)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:101)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:141)
at org.jetbrains.kotlin.backend.jvm.codegen.IrInlineCodegen.genInlineCall(IrInlineCodegen.kt:148)
at org.jetbrains.kotlin.backend.jvm.codegen.IrInlineCallGenerator$DefaultImpls.genCall(IrInlineCallGenerator.kt:29)
...
Caused by: java.lang.IllegalStateException: Couldn't obtain compiled function body for IrBasedSimpleFunctionDescriptor: FUN IR_EXTERNAL_DECLARATION_STUB name:remember visibility:public modality:FINAL <T> (calculation:@[DisallowComposableCalls] kotlin.Function0<T of androidx.compose.runtime.ComposablesKt.remember>) returnType:T of androidx.compose.runtime.ComposablesKt.remember [inline]
at org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.getCompiledMethodNodeInner(InlineCodegen.kt:578)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.access$getCompiledMethodNodeInner(InlineCodegen.kt:542)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.createInlineMethodNode$backend(InlineCodegen.kt:535)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:134)
... 70 more
My simple code looks like this:
@Composable
fun CatalogScreen() {
var currentTab by remember { mutableStateOf(0) }
}
In my project I'm using compose 1.0.1
, kotlin 1.5.21
, gradle 7.1.1
and lot's of plugins and libraries including coroutines and kotlinx serialization, however ugly removing of each dependency doesn't make code working.
Maybe someone met with this kind of error and know what can lead to it or what can break it?
Upvotes: 20
Views: 11475
Reputation: 2205
You might also be missing this from your module's build.gradle file
buildFeatures { // Enables Jetpack Compose for this module
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion versions.composeCompiler
}
Upvotes: 56
Reputation: 127
I am sorry if I am a bit late!
Just check your import statement for remember
Replace import androidx.compose.remember
with import androidx.compose.runtime.remember
and you're done!
Upvotes: -2
Reputation: 2417
Solution was very tricky:
In my buildSrc
buildGradle I had following code:
repositories {
google()
jcenter()
maven(url = "https://storage.googleapis.com/r8-releases/raw")
}
plugins {
`kotlin-dsl`
}
dependencies {
implementation("com.android.tools.build:gradle:7.0.0")
}
Adding api(kotlin("gradle-plugin:1.5.21"))
to dependencies solved build problems.
I'm leaving this clue for other devs who will affect this issue.
Upvotes: 12
Reputation: 6863
I've heard that whenever there's 'an internal backend compiler error', it is originating from the compiler itself, and should be reported. Try creating a new project from Studio Templates and see if it compiles. If it does, then just copy paste your code in that one.
Thanks!
Upvotes: 1