我使用的是Android Studio 4.1 Canary 6版本,我尝试使用apply plugin: 'kotlin-kapt'
插件,然后在构建项目时遇到此错误。
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
此处为项目级别
buildscript {
ext.kotlin_version = "1.3.70"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0-alpha06'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是应用程序级别的Gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
......
......
dependencies {
//room database
implementation 'androidx.room:room-runtime:2.2.5'
implementation "androidx.room:room-ktx:2.2.5"
kapt 'androidx.room:room-compiler:2.2.5'
}
答案 0 :(得分:3)
在使用Compose时,我遇到了同样的问题,因为与kotlinCompilerVersion相比,我为stdlib和gradle插件使用了不同的版本:
// WRONG: Different Kotlin versions
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20"
android {
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.10'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.20"
}
根据我的情况,如果您不使用Compose,我的猜测是存在使用其他Kotlin版本的依赖项(甚至子模块),并且编译器崩溃。似乎与Kotlin的IR后端有关。