Question

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

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

Enquirer: Alex

||

Solution #1:

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

Respondent: Eric

Solution #2:

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**
}
Respondent: Arun Aditya

Solution #3:

You need change:

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

to

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

Solution #4:

I had faced the same issue. The problem was because I was using coroutine suspend functions in the Room DAO and had not implemented the necessary implementations. The following worked for me, try replacing the existing Room dependencies with:

def room_version = "2.2.5" //Use latest version

"androidx.room:room-runtime:$room_version"
"androidx.room:room-compiler:$room_version"
"androidx.room:room-ktx:$room_version"

If the above does not work, go to Analyze->Inspect Code and check for code-breaking warnings or errors(Specifically in Room)

Respondent: Rawlin Crasto

Solution #5:

I had to update Room to latest 2.2.5 and it has resolved the issue.

Respondent: sonique

Solution #6:

Make sure to include all entities inside the Database annotation.

Respondent: Eyosiyas

Solution #7:

In my case I gave the argument type of insertAll() and delete() function as Entity ofyour database, the Error Solved

@Dao
interface NotesDao {

    @Insert
    fun insertAll(INotesEntity: NotesEntity) // argument type should be entity of your database

    @Delete
    fun delete(DNotesEntity: NotesEntity)    // argument type should be entity of your database

}
Respondent: M O N I S H

Solution #8:

This issue occurred on package renaming
I’ve dragged and dropped all files from one package to other.

Objectbox it created the cursor files and entity files (auto-generated files)

Had to delete them and re-built.

It ate up 1 hour straight -_-

Respondent: Prabs

Solution #9:

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"
Respondent: DAEDONGTV ??TV

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy