2

I am building a hilt project and when i am building it, it is giving me this error 'Execution failed for task ':app:kaptDebugKotlin'.

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

  • Try:

Run with --stacktrace option to get the stack trace. Run with --scan to get full insights.

This is the build.gradle file(Module)

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

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.android.practice"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        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'
    }
}

dependencies {

    //hilt
    implementation "com.google.dagger:hilt-android:2.38.1"
    kapt "com.google.dagger:hilt-compiler:2.38.1"

    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.5.0'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

kapt {
    correctErrorTypes = true
}

UserApplication Class

 @HiltAndroidApp
class UserApplication : Application() {

    @Inject
    lateinit var userRepository:UserRepository

    override fun onCreate() {
        super.onCreate()
        userRepository.saveUser("rahmat@gmail.com","pass123")
    }

}

User Repository Class

    class UserRepository @Inject constructor()  {

    fun saveUser(email:String, password:String){
        Log.e("User Repository","User saved")
    }

}

'Error Screenshot [1]: https://i.stack.imgur.com/GDxWe.png

Can anyone help me with this?

Thanks in advance.

Rahmat
  • 21
  • 2

1 Answers1

0

We don't have enought information, try to run this steps to get more information about the error. This topic can help with this link to another topic , I'll bring some information of that topic, resumed, here.

First step is to run the command for Linux ./gradlew clean build and for Windows .\gradlew clean build in Terminal of Android Studio. If it doesn't show the error try the next steps.

To get more info please go to the root item, that in your case is Build: Failed and select to try to get more informations

your root item This should display some helpful error message where to search the error message

If besides this the error doesn't show up try the next step.

In the app/build.gradle add this command kapt { correctErrorTypes true }

OdisBy
  • 15
  • 4