Home > Mobile >  Unable to Run Kotlin App- Execution failed for task ':app:kaptDebugKotlin'
Unable to Run Kotlin App- Execution failed for task ':app:kaptDebugKotlin'

Time:06-08

I keep running my app and it keeps showing the error below:

    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)

The app won't launch on my phone. I have tried to clean the project and running ./gradlew clean but still getting the same error. The app builds successfully but can't run it. Below is my project level gradle file:

    buildscript {
    ext.kotlin_version = '1.7.0-RC2'
    repositories {
        google()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Below is my app level gradle file:

    apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdk 32
    defaultConfig {
        applicationId "com.schatzdesigns.mobileloanappuiconcept"
        minSdkVersion 16
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    buildToolsVersion '33.0.0 rc2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'androidx.appcompat:appcompat:1.6.0-alpha04'
    implementation 'androidx.core:core-ktx:1.9.0-alpha04'
    implementation 'com.google.android.material:material:1.7.0-alpha02'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.vectordrawable:vectordrawable:1.2.0-beta01'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-rc01'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    //noinspection LifecycleAnnotationProcessorWithJava8
    kapt 'androidx.lifecycle:lifecycle-compiler:2.5.0-rc01'

    implementation 'com.google.dagger:dagger:2.35.1'
    implementation 'com.google.dagger:dagger-android:2.35.1'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    kapt 'com.google.dagger:dagger-android-processor:2.16'
    kapt 'com.google.dagger:dagger-compiler:2.16'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.0-alpha04'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha07'
    
}

kapt {
    generateStubs = false
}

CodePudding user response:

The issue is that you are using different versions for dagger-android & dagger-processor causing the kapt issue.

Try using this:

implementation 'com.google.dagger:dagger:2.21'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'

Or if you need to upgrade you dagger version, try using their upgrade guide from here Dagger 2 Releases or upgrade to Dagger Hilt.

  • Related