Kry*_*ski 13 android kotlin android-jetpack-compose
我有一个大项目,我决定向其中添加 jetpack compose。首先,我准备了一个包含一些@Composable
组件的独立项目,一切正常。然后,在编译期间向我的项目添加源和 preper 依赖项后,我开始收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
我的简单代码如下所示:
@Composable
fun CatalogScreen() {
var currentTab by remember { mutableStateOf(0) }
}
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我使用 compose 1.0.1
、 kotlin 1.5.21
、 gradle7.1.1
以及许多插件和库,包括协程和 kotlinx 序列化,但是丑陋地删除每个依赖项并不会使代码正常工作。
也许有人遇到过这种错误,并且知道什么会导致它或什么会破坏它?
Seb*_* LG 35
您的模块的 build.gradle 文件中也可能缺少此内容
buildFeatures { // Enables Jetpack Compose for this module
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion versions.composeCompiler
}
Run Code Online (Sandbox Code Playgroud)
Kry*_*ski 10
解决方案非常棘手:
在我的buildSrc
buildGradle 中,我有以下代码:
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")
}
Run Code Online (Sandbox Code Playgroud)
添加api(kotlin("gradle-plugin:1.5.21"))
依赖项解决了构建问题。
我将这条线索留给其他会影响此问题的开发人员。
我听说每当出现“内部后端编译器错误”时,它都是由编译器本身引起的,应该报告。尝试从 Studio Templates 创建一个新项目并查看它是否可以编译。如果是这样,只需将您的代码复制粘贴到该代码中即可。
谢谢!
归档时间: |
|
查看次数: |
7120 次 |
最近记录: |