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

50,883

Solution 1

You need change:

kapt "android.arch.persistence.room:compiler:$room_version"

to

kapt "androidx.room:room-compiler:$room_version"

Solution 2

Android Studio's UI was just hiding the error...

when the error occurred, it highlighted the item in the list view, and showed an unhelpful message in the terminal view. unhelpful error message appears when erroneous item is selected

to find the real error, select the root item in the list view so that Android Studio would display the whole build output in the terminal view, then scroll to find error. helpful error message appars when you select the root item from the list view on the left

Solution 3

I develop in Apple Silicon Macbook M1.

use room_version 2.2.4, fails in 2.2.5

def room_version = "2.2.4"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
testImplementation "androidx.room:room-testing:$room_version"

Solution 4

This exception occurs when you have done some mistake on Room database or Doa or entity class for example I had done mistakes in the entity class

  1. I had made the autogenerated field of Entity class val instead of var
  2. I had put delete annotation on two functions with a different name but they were deleting the same data

so I would suggest to check the entity,dao or database class carefully if you imported the right dependency.

@Entity(tableName = "user_table")
data class User(
    val firstName: String,
    val lastName: String,
    val age: Int
) {
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0 //**do not made it val**
}

Solution 5

I'm currently having this error on m1 Mac with Room version 2.3.0.

I fixed it by changing it to 2.4.0-alpha04.

This has been reported to Google (issue tracker).

Share:
50,883

Related videos on Youtube

Alex
Author by

Alex

Updated on April 08, 2022

Comments

  • Alex
    Alex about 2 years

    Android studio gave the error:

    Execution failed for task ':app:kaptDebugKotlin'.
    > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
       > java.lang.reflect.InvocationTargetException (no error message)
    

    I want to add in my project Kotlin Coroutines and use it with Room database. But after added all libraries I got this error. This is all information from the compiler.

    I have identified, This is because of the annotation @Database. If I removed this annotation, the error don't appear, but Room is not working too.

    My gradle file:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    //apply plugin: 'androidx.navigation.safeargs'
    
    kotlin {
        experimental {
            coroutines 'enable'
        }
    }
    
    android {
        compileSdkVersion 29
        defaultConfig {
            applicationId "com.bestcred.coursetthree"
            minSdkVersion 21
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            //vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        // Enables data binding.
        buildFeatures {
            dataBinding true
        }
    }
    
    dependencies {
    
    
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    
        // Support libraries
        implementation "androidx.appcompat:appcompat:1.2.0"
        implementation 'com.google.android.material:material:1.2.0'
        implementation "androidx.fragment:fragment:1.2.5"
        implementation "androidx.constraintlayout:constraintlayout:2.0.0"
    
        // Android KTX
        implementation 'androidx.core:core-ktx:1.3.1'
    
        // Room and Lifecycle dependencies
        implementation "androidx.room:room-runtime:$room_version"
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        kapt "android.arch.persistence.room:compiler:$room_version"
    
        // Kotlin Extensions and Coroutines support for Room
        implementation "androidx.room:room-ktx:$room_version"
    
        // Coroutines
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
    
    }
    
    kotlin_version = "1.4.0"
    room_version = "2.2.5"
    coroutine_version = '1.3.9'
    

    I update Room version and add Kotlin Coroutines. What's problem?enter image description here

  • aspro
    aspro over 3 years
    Worked for me. Nothing else did.
  • Jorge Alejandro Puñales
    Jorge Alejandro Puñales over 3 years
    This Answer is valid too for this kind of error. I have an error in a foreign key name, and fixed it solve the problem. Thanks
  • mobibob
    mobibob over 3 years
    Ahhh ... I ran into this before but did not recall the solution. For me to resolve the prior time, I had to setup the command-line build and searched the output. THIS IS MUCH EASIER and more direct!!! Bonus points for you and get a special badge. BTW - my issue is related to @Transaction functions in my Dao object after upgrading the compiler and frameworks (probably room).
  • Alvin Dizon
    Alvin Dizon almost 3 years
    In my case I don't see a list on the left hand side like in your screenshot @Eric
  • Nicolás Carrasco-Stevenson
    Nicolás Carrasco-Stevenson almost 3 years
    I'm also using an M1 and this solved my problem
  • John Doe
    John Doe almost 3 years
    In Android Studio go to Settings (Alt+Ctrl+S) ➡ Build, Execution, Deployment ➡ Build Tools and select the correct Gradle JDK version.
  • Qazi Fahim Farhan
    Qazi Fahim Farhan almost 3 years
    android studio is using java 11, that is ok. but you see, we are working on an android library. The library should be published using github packages. Last time when I had checked, all the tutorials were using the terminal. So in my usecase, I had to build and publish using terminal. That's why I faced the trouble.
  • AnD
    AnD over 2 years
    you save my day. Thanks!
  • vitkuzmenko
    vitkuzmenko over 2 years
    2.3.0 on M1 also fails. 2.2.4 works fine. It fixed in 2.4.0-alpha03
  • Demigod
    Demigod over 2 years
    In my case the error wasn't shown when root item was selected... Doing ./gradlew clean build from the terminal showed the error
  • NightFury
    NightFury over 2 years
    Life saver. Thank you!
  • Astrit Veliu
    Astrit Veliu over 2 years
    Awesome, thank you!
  • user924
    user924 over 2 years
    it's not always the case. I selected build failed but it also doesn't contain anything
  • Nouman Baig
    Nouman Baig over 2 years
    Where and what file you have deleted?
  • Adnan Bal
    Adnan Bal over 2 years
    To the Mac M1 users : this is the right solution for you.
  • Sebastien FERRAND
    Sebastien FERRAND over 2 years
    That was my issue. Saved my life
  • Sanjayrajsinh
    Sanjayrajsinh about 2 years
    on which tag we need to add this ?
  • lomec
    lomec about 2 years
    And the other way around for me it was 11 and 8 needed. Thanks for the tip
  • Prabs
    Prabs about 2 years
    Auto generated files @NoumanBaig
  • CoolMind
    CoolMind almost 2 years
    Thanks, @JohnDoe! I changed Java from 11 to 15 in settings.
  • CoolMind
    CoolMind almost 2 years
    How is that possible? It will be a compile error.