Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 4.1 Canary 6 issue with kapt plugin (e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState)

I use Android Studio 4.1 Canary 6 version and I'm try to use apply plugin: 'kotlin-kapt' plugin then I got this error during build project.

e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;

here project level 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
}

And here is the app level 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'
}
like image 699
code4rox Avatar asked Apr 18 '20 11:04

code4rox


1 Answers

I had the same issue when using Compose because I was using a different version for the stdlib & gradle plugin compared to kotlinCompilerVersion:

// 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"
}

Based in my case, if you are not using Compose my guess is that there is a dependency (or even a submodule) that is using a different Kotlin version and the compiler crashes. It seems something related to Kotlin's IR backend.

like image 122
Abdelilah El Aissaoui Avatar answered Oct 20 '22 05:10

Abdelilah El Aissaoui