【问题标题】:Couldn't inline method call 'remember'无法内联方法调用“记住”
【发布时间】:2021-08-14 13:20:57
【问题描述】:

您能否告知代码有什么问题:我在构建时遇到 JVM 错误:

Kotlin 版本 = 1.5.21

撰写版本 = 1.0.1

原因:org.jetbrains.kotlin.codegen.CompilationException:后端(JVM)内部错误:无法将内联方法调用“记住”到 @androidx.compose.runtime.Composable public fun TelephoneEditText($composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int): com.example.scrapper.ui 中定义的kotlin.Unit 原因:未生成 文件未知 引发 java.lang.IllegalStateException 的根本原因是:org.jetbrains.kotlin.codegen.inline.InlineCodegen$Companion.getCompiledMethodNodeInner(InlineCodegen.kt:578) 在 org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:101) 在 org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:141)

@Preview
@Composable
fun TextEditOnScreen() {
    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        TelephoneEditText()
    }
}

@Composable
fun TelephoneEditText() {
    val textValue = remember {
        mutableStateOf("")
    }
    val primaryColor = colorResource(id = R.color.design_default_color_primary)

    OutlinedTextField(
        label = { Text(text = stringResource(id =
        R.string.phoneNumber)) },
        colors = TextFieldDefaults.outlinedTextFieldColors(
            focusedBorderColor = primaryColor,
            focusedLabelColor = primaryColor,
            cursorColor = primaryColor
        ),
        keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
        value = textValue.value,
        onValueChange = {textValue.value = it},
    )
}

已解决

替换:

implementation 'androidx.ui:ui-foundation:0.1.0-dev14'

implementation "androidx.compose.foundation:foundation:$compose_version"

【问题讨论】:

标签: android kotlin android-jetpack-compose


【解决方案1】:

您的撰写代码完全没问题。

问题可能出在您的依赖项或 gradle 设置中

尝试创建一个新的 compose 项目,看看它是否能重现。

如果运行良好,请比较 gradle 设置以找出不同之处

如果不起作用,请考虑将其报告给compose issue tracker,并附上示例项目的 AS 日志和代码

【讨论】:

  • 你是对的,不正确的依赖引起的问题:用实现“androidx.compose.foundation:foundation:$compose_version”替换了实现'androidx.ui:ui-foundation:0.1.0-dev14' " 构建成功
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-16
  • 2018-08-23
  • 1970-01-01
  • 1970-01-01
  • 2019-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多