Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't inline method call 'remember' into @androidx.compose.runtime.Composable

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?

like image 439
Krystian Kaniowski Avatar asked Sep 14 '25 05:09

Krystian Kaniowski


1 Answers

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
}
like image 114
Sebas LG Avatar answered Sep 15 '25 18:09

Sebas LG