Android Studio 4.1 Canary 6 问题与 kapt 插件(e : java. lang.NoSuchMethodError : org. jetbrains.kotlin.codegen.state.GenerationState)

标签 android android-studio kotlin-android-extensions

我使用 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/

相关文章:

android - 如何在android中打开链接?

android - 如何设置自定义对话框内的onclicklistener按钮

android - 为 multidexed 应用程序禁用即时运行

android - Android 扩展中的实验性功能有利于生产版本

android - 为什么在匿名子类上使用 Kotlin "by"?

android - 在 scrollView android 上实现缩放

java - 你们支持 Android 应用程序有多早?

java - 渲染问题 Android Studio

Android Studio 在红线中提示 "Cannot access androidx.activity.ComponentActivity"但编译正常

android - 程序类型已经存在 : org. intellij.lang.annotations.Flow