java.lang.reflect.InvocationTargetException (no error message) for task ':app:kaptDebugKotlin'
Asked Answered
B

5

8

i ran into following error an cannot find an solution.

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 cannot say, what I have done last time, probably there is some library causing this error which i had updated. Build Gradle

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

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.padder.application"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        viewBinding true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    implementation "androidx.core:core-ktx:$ktxVersion"
    implementation "androidx.appcompat:appcompat:$appCompatVersion"
    implementation "com.google.android.material:material:$materialVersion"
    implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$testExtJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"

    // Fragment
    implementation "androidx.fragment:fragment-ktx:$fragmentVersion"

    // Navigation Component
    implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

    // Lifecycle + ViewModel & LiveData
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
    implementation "android.arch.lifecycle:common-java8:$lifecycleVersion"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"

    // DataStore
    implementation "androidx.datastore:datastore-preferences:$dataStoreVersion"

    // Room
    implementation "androidx.room:room-runtime:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"
    implementation "androidx.room:room-ktx:$roomVersion"

    // Dagger Hilt
    implementation "com.google.dagger:hilt-android:$hiltVersion"
    kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hiltAndroidXVersion"
    kapt "androidx.hilt:hilt-compiler:$hiltAndroidXVersion"
}

kapt {
    correctErrorTypes true
}

These are my librarys + versions. Hopefully this helps. I give you the full error log as well, so you have, what I have.

Executing tasks: [:app:assembleDebug] in project C:\Users\Nutzer\Desktop\IntelliJ_Projects\Application

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
[TASKS]
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:validateSigningDebug UP-TO-DATE           ^
> Task :app:kaptDebugKotlin FAILED

FAILURE: Build failed with an exception.

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 28s
21 actionable tasks: 2 executed, 19 up-to-date

Because inside the error is the Database mentioned, I give it as well.

package com.padder.application.data

import androidx.room.Database
import androidx.room.RoomDatabase
import javax.inject.Inject

@Database(entities = [Table1::class , Table2::class], version = 1) //exportSchema = false  is not working
abstract class Database : RoomDatabase() {

    abstract fun dao(): Dao
}

Just say if you need more snippeds, but hopefully these arent to much snippets that you not run away.

As wished here is the Dao I use:

package com.padder.application.data

import androidx.room.*
import kotlinx.coroutines.flow.Flow

@Dao
interface Dao {
    /**
     * SQL-Sort
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(item: Item)

    @Update
    suspend fun update(item: item)

    @Delete
    suspend fun delete(item: Item)

    // Searchqueries LIST-Fragment
    fun getItemList(sortState: SortSpinnerState, item: String, search: String) : Flow<List<Item>> =
        when (sortState) {
            SortSpinnerState.BY_NAME -> getItemListSortName(item, search)
            SortSpinnerState.BY_TASTE -> getItemListSortTaste(item, search)
            SortSpinnerState.BY_FAV -> getItemListSortFav(item, search)
            SortSpinnerState.BY_LIKE -> getItemListSortLike(item, search)
        }

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE marke = :marke AND name LIKE '%' || :search || '%' ORDER BY name ASC")
    fun getItemListSortName(marke: String, search: String): Flow<List<Item>>

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE marke = :marke AND name LIKE '%' || :search || '%' ORDER BY taste ASC")
    fun getItemListSortTaste(marke: String, search: String): Flow<List<Item>>

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE marke = :marke AND name LIKE '%' || :search || '%' ORDER BY fav = 1 DESC, name ASC")
    fun getItemListSortFav(marke: String, search: String): Flow<List<Item>>

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE marke = :marke AND name LIKE '%' || :search || '%' ORDER BY like = 1 DESC, like = 2 DESC, like = 3 ASC, name ASC")
    fun getItemListSortLike(marke: String, search: String): Flow<List<Item>>

    // Searchqueries HOME-Fragment
    fun getItemListHome(state: SearchByState, search: String) : Flow<List<Item>> =
        when (state) {
            SearchByState.BY_NAME -> getItemListHomeName(search)
            SearchByState.BY_TASTE -> getItemListHomeTaste(search)
            SearchByState.NO_SEARCH -> getItemListHomeNone()
        }

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE name LIKE '%' || :search || '%' ORDER BY name ASC")
    fun getItemListHomeName(search: String): Flow<List<Item>>

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE geschmack LIKE '%' || :search || '%' ORDER BY taste ASC")
    fun getItemListHomeTaste(search: String): Flow<List<Item>>

    @Query("SELECT nr, name, taste, marke, mag, fav FROM tabak WHERE nr = 0 ORDER BY taste ASC")
    fun getItemListHomeNone(): Flow<List<Item>>

    /**
     * SQL-Marke
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(marke: Marke)

    @Update
    suspend fun update(marke: Marke)

    @Delete
    suspend fun delete(marke: Marke)

    @Query("SELECT marke FROM marke ORDER BY nr")
    suspend fun getMarkeListe(): List<String>

    @Query("SELECT nr FROM marke WHERE marke = :marke")
    suspend fun getMarkeNr(marke: String): Int
}

So my question. Can you help me to get rid of this error? What did I just do wrong, or what can I do to handle it.
Thank you!

Bridle answered 26/1, 2021 at 13:0 Comment(6)
can you add more code of the Database classTessy
Thats all of the Database class. I do not add a callback.Bridle
can you paste Dao interface code in the question?Tessy
Dao successfully addedBridle
I'm having the same problem with Android's Room codelab, so it doesn't have to do with Dagger specifically, in my case it was having the wrong parameter type in the Dao function marked @Delete (I put id instead of item). I don't see anything wrong with yours, but I would guess the error is due to the code generator not being able to apply the annotation to the function. I don't know SQL that well, but I'm suspicious of your "ORDER BY like=1 DESC"Hebbe
Hello alr3000, wow thank you for these information. These all sql statements works very good, with all sorting statements. To find this error, i comment out every sql statement, but not gone. :(Bridle
B
-1

and user with same problem,

the gotten error is because updated the libraries and is causing by an annotation inside the viewholder.

@ViewModelInject is depricated and needs do replaced by @Inject and the class needs to be annotated with @HiltViewModel.

for example:
old: DEPRECATED

class MainViewModel @ViewModelInject constructor() : ViewModel() { ... }

new:

@HiltViewModel
class MainViewModel @Inject constructor() : ViewModel() { ... }

now everything work fine again :))

Have a nice day

Bridle answered 17/2, 2021 at 19:23 Comment(0)
R
5

If some library is using kapt for annotation processing, make sure the library and its annotation processor version are the same.

For me, the following was causing the error (Version mismatch):

implementation 'com.google.dagger:dagger:2.38.1'
kapt 'com.google.dagger:dagger-compiler:2.34.1'

This works (Notice the version is same):

implementation 'com.google.dagger:dagger:2.38.1'
kapt 'com.google.dagger:dagger-compiler:2.38.1'
Runin answered 19/12, 2021 at 12:24 Comment(1)
In my case, it was a problem related to the dependencies that had been added using kapt. I removed them and now is working. Also, in my case, these dependencies were not necessary, luckily.Diez
D
4

People may already know this but I only recently happened on this godsend, due to the vagueness of Android Studio error messages. Open a terminal window in Android Studio and type the following at the prompt. ./gradlew build -stacktrace

Work back on the ensuing stacktrace and it will show you precisely what the errors were. BAM! Problem identified and solved!

Dossal answered 5/6, 2022 at 16:17 Comment(0)
P
3

kapt Error showing when I used compileSdkVersion 31 instead of 30

When I changed to 30, the error disappear

Postmistress answered 9/10, 2021 at 7:17 Comment(1)
android { compileSdkVersion 30 buildToolsVersion "30.0.0"Postmistress
W
1

I fixed it with adding missing annotations in Hilt Module

@Module //It was missing 
@InstallIn(SingletonComponent::class) //It was missing 
object NetworkModule {

   @Singleton
   @Provides
   fun getRetrofitApi(): ApiInterface = Retrofit.Builder()
       .baseUrl(BASE_URL)
       .addConverterFactory(GsonConverterFactory.create())
       .build()
       .create(ApiInterface::class.java)
}
Wingspan answered 1/7, 2021 at 8:40 Comment(0)
B
-1

and user with same problem,

the gotten error is because updated the libraries and is causing by an annotation inside the viewholder.

@ViewModelInject is depricated and needs do replaced by @Inject and the class needs to be annotated with @HiltViewModel.

for example:
old: DEPRECATED

class MainViewModel @ViewModelInject constructor() : ViewModel() { ... }

new:

@HiltViewModel
class MainViewModel @Inject constructor() : ViewModel() { ... }

now everything work fine again :))

Have a nice day

Bridle answered 17/2, 2021 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.