Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
Asked Answered
S

7

11

I'm getting this not very informative error while building my project in Android Studio. I've tried everything from stackoverflow but nothing works.

Execution failed for task ':app:kaptDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message)

My app gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-parcelize'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'




}



android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {

        configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }

        applicationId "com.nenad.favrecipes"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    android {
        buildFeatures {
            dataBinding true
        }

    }


    dependencies {

        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" //1.5.21
        implementation 'androidx.core:core-ktx:1.6.0'
        implementation 'androidx.appcompat:appcompat:1.3.0'
        implementation 'com.google.android.material:material:1.4.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        testImplementation 'junit:junit:4.+'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

        implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
        implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'


        implementation 'com.squareup.retrofit2:retrofit:2.9.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
        implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

        implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"

        // RxJava
        implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
        implementation 'io.reactivex.rxjava3:rxjava:3.0.0'

        implementation "com.squareup.retrofit2:retrofit:2.9.0"
        implementation "com.squareup.retrofit2:converter-scalars:2.9.0"
        implementation "com.squareup.retrofit2:converter-moshi:2.9.0"

        implementation "com.squareup.okhttp3:okhttp:4.9.1"
        implementation "com.squareup.okhttp3:logging-interceptor:4.9.1"
        implementation "com.squareup.okhttp3:okhttp-urlconnection:4.2.1"

        implementation 'androidx.multidex:multidex:2.0.1'

        implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

        //shimmering RV
        implementation 'com.facebook.shimmer:shimmer:0.5.0'
        implementation 'com.todkars:shimmer-recyclerview:0.4.1'

        implementation 'com.google.code.gson:gson:2.8.7'

        implementation 'com.google.dagger:hilt-android:2.40.5'
        kapt 'com.google.dagger:hilt-compiler:2.40.5'

        implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

        // DataStore
        implementation "androidx.datastore:datastore-preferences:1.0.0"
        implementation "androidx.datastore:datastore:1.0.0"

        implementation("androidx.fragment:fragment-ktx:1.3.0")

        def room_version = '2.3.0'
        implementation "androidx.room:room-runtime:$room_version"
        kapt "androidx.room:room-compiler:$room_version"
    }
    kapt {
        correctErrorTypes true
    }
}

My project gradle:

buildscript {
    ext.kotlin_version = "1.3.72" 
    repositories {
        google()
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3' //4.1.3
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
plugins {

    id "org.jetbrains.kotlin.android" version "1.4.20" apply false
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Savoie answered 16/2, 2022 at 0:47 Comment(1)
I have the same problem. Do you find anything to solve the issue?Bespatter
K
10

Change the JDK Version of Android Studio and try it Go to file-> Project Structure-> SDK Location -> Click the Gradle Settings

a busy cat

Kahl answered 1/6, 2022 at 8:40 Comment(0)
E
8

If you are using the room on a Mac M1 chip Make sure you use room version 2.4.0-alpha03 or more.

As mentioned by jetpack (Version 2.4.0-alpha03 )

Fixed an issue with Room’s SQLite native library to support Apple’s M1 chips. Change Version to 2.4.0-alpha03 or above

implementation "androidx.room:room-runtime:2.4.0-alpha03"
annotationProcessor "androidx.room:room-compiler:2.4.0-alpha03"
kapt 'androidx.room:room-compiler:2.4.0-alpha03'
Eirena answered 18/10, 2022 at 10:47 Comment(1)
it works,thanks. M1 Mac,change the room version from 2.3.0 to 2.4.0-alpha03 fixed the errorSuperfuse
G
5

For me what worked was updating hilt libraries to the latest version.

Both classpath in project gradle

classpath("com.google.dagger:hilt-android-gradle-plugin:2.48")

and in app gradle

implementation("com.google.dagger:hilt-android:2.48")
kapt("com.google.dagger:hilt-android-compiler:2.48")

Make sure you are using the same version in both project gradle classpath and app gradle.

Sometimes Android Studio doesn't warn us to update to the latest version of dependencies and we might think that we are using the latest version but it might not be and Android Studio will keep throwing errors and waste our time. Finally, the problem was fixed after updating to the latest version.

To get the latest version of hilt dependencies, check this URL.

Guitar answered 9/11, 2023 at 6:6 Comment(1)
It worked for me. I was trying all the other solutions, but none of them worked. After updating the hilt version, everything is working.Harborage
S
3

Your app level module should be something like below:

build.gradle(:app)

buildscript {
repositories {
    google()
    mavenCentral()

}
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.3' //4.1.3
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
    classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
 }
}
 task clean(type: Delete) {
    delete rootProject.buildDir
}

And, another gradle file should be like something like below:

build.gradle(:app)

plugins {
   id 'com.android.application'
   id 'kotlin-android'
   id 'kotlin-parcelize'
   id 'kotlin-kapt'
   id 'dagger.hilt.android.plugin'
}


android {
   compileSdkVersion 30
   buildToolsVersion "30.0.3"

   defaultConfig {

    configurations.all {
        resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
    }

    applicationId "com.nenad.favrecipes"
    minSdkVersion 23
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}

buildFeatures {
    dataBinding true
}


dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.21" //1.5.21
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'


    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"

    // RxJava
    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.0'

    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-scalars:2.9.0"
    implementation "com.squareup.retrofit2:converter-moshi:2.9.0"

    implementation "com.squareup.okhttp3:okhttp:4.9.1"
    implementation "com.squareup.okhttp3:logging-interceptor:4.9.1"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:4.2.1"

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

    //shimmering RV
    implementation 'com.facebook.shimmer:shimmer:0.5.0'
    implementation 'com.todkars:shimmer-recyclerview:0.4.1'

    implementation 'com.google.code.gson:gson:2.8.7'

    implementation 'com.google.dagger:hilt-android:2.40.5'
    kapt 'com.google.dagger:hilt-compiler:2.40.5'

    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    // DataStore
    implementation "androidx.datastore:datastore-preferences:1.0.0"
    implementation "androidx.datastore:datastore:1.0.0"

    implementation("androidx.fragment:fragment-ktx:1.3.0")

    def room_version = '2.3.0'
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
}
kapt {
    correctErrorTypes true
  }
}
Saxhorn answered 16/2, 2022 at 1:30 Comment(0)
P
2

I was facing a similar issue on my Mac M1 Max chip, and it was resolved by changing the versions of the Kotlin and Room libraries.

Initially, I was using Kotlin version 1.8.21 and Room version 2.2.5, but after updating to Kotlin version 1.3.72 and Room version 2.4.2, the issue was resolved.

project level build.gradle :

buildscript {
    ext.kotlinVersion = '1.3.72'
}
ext {
  roomVersion = '2.4.2'
}

Hopefully, this solution will work for others and save them some time :)

Pendergast answered 8/5, 2023 at 15:3 Comment(0)
C
0

If still any one facing the same issue then add the following line in build.gradle(App), this one is solved my issue

kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2"
Caernarvonshire answered 26/9, 2023 at 18:29 Comment(0)
C
0

Replacing kapt with annotationProcessor in build.gradle resolved this error for me

annotationProcessor ("com.google.dagger:dagger-compiler:2.40.5")
annotationProcessor ("com.google.dagger:dagger-android-processor:2.40.5")
Codi answered 23/7, 2024 at 7:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.