我使用 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;
这里项目级gradle
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'
}
最佳答案
我在使用 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 后端有关。
关于Android Studio 4.1 Canary 6 问题与 kapt 插件(e : java. lang.NoSuchMethodError : org. jetbrains.kotlin.codegen.state.GenerationState),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61288245/