Error:Execution failed for task ':app:kaptDebugKotlin'
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
- Database declarations
- Data Access Object declarations
- Data class fields
It's a problem arising due to improper usage of annotations of Room. For more information use your build logs.
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
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
leggo
Updated on April 26, 2022Comments
-
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 over 6 yearsSwitch 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 over 3 yearsconvert all related classes to kotlin
-
-
Zeshan Sajid over 5 yearsi tried. it starts downloading the same gradle version zip which is already installed and activated.
-
Mehroze Yaqoob about 5 yearsfor windows user, use backslash. Something like .\gradlew clean build
-
Osman Yalın about 4 yearsThat one fixed my problem. Thanks a lot!
-
user2323471 about 4 yearsIt fixed my problem. Kudos !! :)
-
Siamak over 3 yearsuse
chmod +x ./gradlew
before if it's your first time calling gradlew in linux. -
Antroid over 3 yearsAmazing. This really helped to see what errors needs to be fixed. Thanks!
-
mobibob over 3 yearsIt 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 over 3 yearsIf some error occur in the SQL statement of the Dao , also get the error
-
NimaAzhd about 3 yearsI 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 about 3 yearsIn my case backslash
.\gradlew clean build
ORgradlew clean build
is working. -
Sina Mirshafiei almost 3 yearsIt's work! after a lot of search, your solution fixed my problem, Thank you!!!!
-
Yunnosch over 2 yearsPlease 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 over 2 yearsWow. This really helped me to find the issue.
-
Yunnosch over 2 yearsWhile 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 over 2 yearsThanks, this really helped me.
-
awaqar over 2 yearsI 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 about 2 yearsfor me the problem was not the dagger, but upvoted for command line options
-
David Read about 2 yearsThis worked for me too. Can anyone give insight on why? I thought the kapt plugin provided all the annotations Dagger needed.
-
ghifari.akbar about 2 years@Yunnosch not really. it's up to him what he wants to do