Execution failed for task ':app:kaptGenerateStubsDebugKotlin' after android studio V3.1.1 update
Asked Answered
U

5

17

I just updated android studio to V3.1.1. Then my program went wrong. When build the program,there are two errors:

enter image description here

  1. One in 'Run build':

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'

enter image description here

  1. Another in Java compiler:

java.lang.ClassNotFoundException: org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker

enter image description here

Here is my gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-android-extensions'




android {
    compileSdkVersion 26


    defaultConfig {
        applicationId "com.restress.saniauto"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    buildToolsVersion '27.0.3'
}


androidExtensions {
    experimental = true
}


buildscript {
    ext.kotlin_version = '1.2.21'
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }
    dependencies {
        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.22.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //RxJava
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
    implementation 'io.reactivex:rxkotlin:0.55.0'
    //Room & RxAndroid2
    implementation "android.arch.persistence.room:runtime:$room_version"
    implementation "android.arch.persistence.room:rxjava2:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation "android.arch.persistence.room:testing:$room_version"
    //Design
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:percent:26.1.0'
  
}
Uvea answered 14/4, 2018 at 12:28 Comment(4)
Did you tried a clean build? (aka rebuild)Hanna
yes,but clean&rebuild didnt work.Uvea
failed again,still the same errorsUvea
Open <root project>/gradle/wrapper/gradle-wrapper.properties and read Gradle version. It should be at least 4.4. If that doesn't work try 4.6.Leary
U
5

Well,I finally get over this. When I use --stacktrace,I find the :app:kaptDebugKotlin is a procedure in BUILDING an android program. --stacktrace result picture

And I get the error java.lang.ClassNotFoundException: org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker in this :app:kaptDebugKotlin procedure.

I doubt that there're something new in kotlin implementation,so I update my kotlin_version from 1.2.21 to 1.2.30.

Then I get more clear errors.That is the room parameters errors. room error

So I change the arg0 to the parameter name in Dao functions in SQL query.

Finally it works.

Uvea answered 16/4, 2018 at 4:25 Comment(3)
@resress: I'm beginner android dev, can you explain how to using --stacktrace? because I have same error and still doesn't work for me.Epaulet
./gradlew build --stacktraceJez
Updating kotlin version helped.Selfrising
W
0

I was working on the test project. Using dagger with Kotlin and this task failing was a blocker.

I tried many ways but the error message was not meaningful, the very next day I Start copying classes to a new project and found that issue is due to dagger and also convert Moshi annotation @JsonClass(generateAdapter = true) java class into Kotlin.

MoviesViewModel @Inject constructor(private val movieService: MovieService): ViewModel()

then :)

Whitherward answered 22/4, 2019 at 1:40 Comment(0)
I
0

I had the same error and solved by updating the kotlin to the latest version (1.5.31) in my project build.gradle:

buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
    }
}
Institutional answered 14/10, 2021 at 10:56 Comment(0)
S
0

For people trying to use Jetpack Compose running into this error.

For me I was missing the composeOptions{...} block so I added it as shown below and the error is resolved now.

buildFeatures {
    compose = true
    viewBinding = true
}

composeOptions {
    kotlinCompilerExtensionVersion = "1.0.1"
    kotlinCompilerVersion = "1.5.21" // Make sure this version is same as your Kotlin version
}
Steffi answered 13/9, 2022 at 10:56 Comment(0)
K
0

In my case, I downgrade the kotlin plugin version from 1.8.20 to 1.7.20 in build.gradle in root project like below:

plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
Knifeedged answered 28/7, 2023 at 2:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.