7

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
}
Nenad Vukojevic
  • 73
  • 1
  • 1
  • 4

4 Answers4

9

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

a busy cat

Pankaj Jangid
  • 121
  • 1
  • 6
5

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'
Bharat Lalwani
  • 1,277
  • 15
  • 17
2

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
  }
}
Rudra Rokaya
  • 637
  • 1
  • 5
  • 9
0

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 :)