Error:Execution failed for task ':app:kaptDebugKotlin'

99,568

Solution 1

Run your application with ./gradlew clean build command to see what's exactly wrong with your code. Just paste it into the Terminal in Android Studio.

Solution 2

If you are using the Room database and getting a KAPT error, just check your

  1. Database declarations
  2. Data Access Object declarations
  3. Data class fields

It's a problem arising due to improper usage of annotations of Room. For more information use your build logs.

You can see here in this picture before expanding the error log, I can see the annotation missing error.

Solution 3

I faced this problem for a while. What helped me a lot was reading the build tab because it gave the reasons the library was failing.
Here is the tab Build tab I had many problems,
1. I haven't added the new entity I created into the @Database annotation
2. I haven't added the @Dao annotation in my interface
3. I haven't updated some variables names that was wrote in a @Query annotation
So I had to kill problem by problem, finally it could run later. In Addition, I was cleaning my project and rebuilding to ensure code doesn't get stuck. Also close and open Android Studio.

Futhermore, you can check this answer to help you find the error enable more log on error

Solution 4

I faced this problem for a while. My mistake was using private access specifier with @Inject field.

If you are using Dagger then check for @Inject private fields or to know the exact cause add this as Command-line options:

--stacktrace --info --scan

On Mac, go to Android Studio > Preferences > Build, Execution, Deployment > Compiler

On Windows, go to File > Settings > Build, Execution, Deployment > Compiler

Solution 5

In my case I replaced this

implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'

by

implementation 'com.google.dagger:dagger:2.27'
annotationProcessor "com.google.dagger:dagger-compiler:2.27"

and solved the problem

Share:
99,568
leggo
Author by

leggo

Updated on April 26, 2022

Comments

  • leggo
    leggo about 2 years

    I'm new to using Kotlin and trying to set it up with Dagger2, I've seen some few examples but none of them seem to work for me.

    I keep getting this

    Error:Execution failed for task ':app:kaptDebugKotlin'.

    Internal compiler error. See log for more details

    I have my build.gradle (Module: app)

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'kotlin-android-extensions'
    
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.0"
        defaultConfig {
            applicationId "com.exampleapp"
            minSdkVersion 14
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        kapt {
            generateStubs = true
        }
        dexOptions {
            javaMaxHeapSize "2048M"
        }
    }
    
    ext {
        supportLibVer = '25.0.0'
        daggerVer = '2.8'
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        // Support lib
        compile "com.android.support:appcompat-v7:${supportLibVer}"
    
        kapt "com.google.dagger:dagger-compiler:${daggerVer}"
        compile "com.google.dagger:dagger:${daggerVer}"
        provided "javax.annotation:jsr250-api:${javaxVer}"
    
        compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    
    
    }
    repositories {
        mavenCentral()
    }
    
    • David Medenjak
      David Medenjak over 6 years
      Switch to the gradle console and look at the log output. The IDE only shows you that there was an error compiling, but you have to look at the output to see the error.
    • Shahab Saalami
      Shahab Saalami over 3 years
      convert all related classes to kotlin
  • Zeshan Sajid
    Zeshan Sajid over 5 years
    i tried. it starts downloading the same gradle version zip which is already installed and activated.
  • Mehroze Yaqoob
    Mehroze Yaqoob about 5 years
    for windows user, use backslash. Something like .\gradlew clean build
  • Osman Yalın
    Osman Yalın about 4 years
    That one fixed my problem. Thanks a lot!
  • user2323471
    user2323471 about 4 years
    It fixed my problem. Kudos !! :)
  • Siamak
    Siamak over 3 years
    use chmod +x ./gradlew before if it's your first time calling gradlew in linux.
  • Antroid
    Antroid over 3 years
    Amazing. This really helped to see what errors needs to be fixed. Thanks!
  • mobibob
    mobibob over 3 years
    It appears that for every new project, I have these massive build errors and each time is for a different (some times dumb) reason. This technique, using the command line parameter, allowed me to see my error using Float in the annotations for my Dao / Database (using Room). ./gradlew clean build --debug --stacktrace
  • BertKing
    BertKing over 3 years
    If some error occur in the SQL statement of the Dao , also get the error
  • NimaAzhd
    NimaAzhd about 3 years
    I worked with persistence room before , when I added hilt dependency it caused unknown error, it took 2 days me until I found your comment, Thanks,
  • Shashi Shiva L
    Shashi Shiva L about 3 years
    In my case backslash .\gradlew clean build OR gradlew clean build is working.
  • Sina Mirshafiei
    Sina Mirshafiei almost 3 years
    It's work! after a lot of search, your solution fixed my problem, Thank you!!!!
  • Yunnosch
    Yunnosch over 2 years
    Please phrase this as an explained conditional answer, in order to avoid the impression of proposing a debugging experiment instead of answering (for which a comment should be used instead of an answer, compare meta.stackexchange.com/questions/214173/… ). For example like "If your problem is ... then the solution is to .... because .... ."
  • Naimul Kabir
    Naimul Kabir over 2 years
    Wow. This really helped me to find the issue.
  • Yunnosch
    Yunnosch over 2 years
    While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
  • King Of The Jungle
    King Of The Jungle over 2 years
    Thanks, this really helped me.
  • awaqar
    awaqar over 2 years
    I was going to comment that until I found your comment. Indeed, I updated the room uplifted versions from 2.3.0 to 2.4.1 and it worked: implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version"
  • Reza
    Reza about 2 years
    for me the problem was not the dagger, but upvoted for command line options
  • David Read
    David Read about 2 years
    This worked for me too. Can anyone give insight on why? I thought the kapt plugin provided all the annotations Dagger needed.
  • ghifari.akbar
    ghifari.akbar about 2 years
    @Yunnosch not really. it's up to him what he wants to do