A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

247,604

Solution 1

Android Studio's UI was just hiding the error...

when the error occurred, it highlighted the item in the list view, and showed an unhelpful message in the terminal view. bad bad

to find the real error, select the root item in the list view so that Android Studio would display the whole build output in the terminal view, then scroll to find error. good good

Solution 2

Maybe I am a bit late for the answer but, anyways, I was getting the same error. The build failure can be caused by some error that Android Studio fails to point out probably due the the project size being very large.

Here is the easy way to point out the exact error.

  1. In Android studio go to Analyze menu and click on Inspect Code; check whole project, click OK and wait for the inspection to finish.

    Inspect Code

  2. Now you will see a tab that will point all the errors, warnings etc and you can now resolve the real issue.

    Errors tab

Solution 3

The way to find out what the underlying issue is, is to run the following command :

./gradlew assembleDebug --stacktrace

Solution 4

Change

implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"

To (updated 4 - September-2021)

 implementation "androidx.room:room-runtime:2.3.0"
 annotationProcessor "androidx.room:room-compiler:2.3.0"

Solution 5

I started getting this after upgrading my Android Studio to Arctic Fox(2020.3.1).

I resolved it by updating my JDK version from 1.8 to Embedded JDK.

To change the JDK:

  • Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle

  • On Mac: Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle.

  • Under Gradle JDK, choose the Embedded JDK option.

As mentioned here

Share:
247,604

Related videos on Youtube

Shubham Tater
Author by

Shubham Tater

Updated on May 13, 2022

Comments

  • Shubham Tater
    Shubham Tater 7 months

    All of sudden I start getting this error, and I am not getting idea why if anyone just let me know where this error is, will be enough helpful. As much I am able to get is this because of new update of android studio. Detailed summary of error I am getting.

    Task :app:kaptDebugKotlin
        ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1C:\Users\shubh\Downloads\MarginCalculator\app\build\generated\source\kapt\debug\com\kotlin_developer\margincalculator\DataBinderMapperImpl.java:10: error: cannot find symbol
        import com.kotlin_developer.margincalculator.databinding.FragmentCalculatorScreenBindingImpl;
        symbol:   class FragmentCalculatorScreenBindingImpl
        Task :app:kaptDebugKotlin FAILED
        location: package com.kotlin_developer.margincalculator.databinding
        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 17s
    29 actionable tasks: 27 executed, 2 up-to-date
    
    • Sergio
      Sergio over 2 years
      please show your code in build.gradle file.
    • Sergio
      Sergio over 2 years
      please show DataBinderMapperImpl.java code as well.
    • Samuel Eminet
      Samuel Eminet over 2 years
      Have you updated to Android Studio 4? same pb here
    • Hani
      Hani over 2 years
      I updated to Android Studio 4 and I've been getting the same error with using Room, I was able to temporarily fix it by changing one of my queries. I initially had this query: "SELECT case_name FROM SavedCases", and then changed it to "SELECT * FROM SavedCases", and the error message went away. For some reason, I only get this error when I try to query only specific columns. This is not an ideal fix for the problem and I hope someone has a better fix.
    • Mustaqode
      Mustaqode over 2 years
      I had a similar error and found a solution that works for me. You might have done something similar. stackoverflow.com/questions/63133657/…
    • Dan Alboteanu
      Dan Alboteanu over 2 years
      for me it was the primary constructor in one database entry class
    • Nagaraj Alagusundaram
      Nagaraj Alagusundaram over 2 years
      I'm getting this error after migrating to AndroidX
    • Achraf Amil
      Achraf Amil over 2 years
      There might be many reasons since error message is not explicit. Mine was make an @Inject field private with dagger-hilt.
    • Arbaz.in
      Arbaz.in almost 2 years
      i am facing the same issue for realm any solution ?
    • solidogen
      solidogen 11 months
  • Shubham Tater
    Shubham Tater over 2 years
    This is not the proper solution
  • Mujeeb Rahaman T
    Mujeeb Rahaman T over 2 years
    @ShubhamTater This is solution till gradle4.0.0 is to be fixed. This is the temporary solution . Once gradle4.0.0 is fixed . We can update the gradle 4.0 or more
  • Shubham Tater
    Shubham Tater over 2 years
    I got the solution for my problem, I dont know wether it will work for you or not but the soultion is check your XML file which you are binding, binding is a compile time system, and it work for XML file so check it if their is any error in it it will show this type of error. I correct my XML file then everything work perfectly.
  • Shubham Tater
    Shubham Tater over 2 years
    I got the solution for my problem, I dont know wether it will work for you or not but the soultion is check your XML file which you are binding, binding is a compile time system, and it work for XML file so check it if their is any error in it it will show this type of error. I correct my XML file then everything work perfectly.
  • Shubham Tater
    Shubham Tater over 2 years
    Right this error is always related to XML file which our databinding is using.
  • Ярослав Нестеров
    Ярослав Нестеров over 2 years
    I caught this exception on 4.0.1
  • Mustaqode
    Mustaqode over 2 years
    What kind of mistakes?
  • Bolt UIX
    Bolt UIX over 2 years
    yes, it is showing exactly error. (i made some mistake in XML)
  • Simo Nyathi
    Simo Nyathi over 2 years
    Yes please. how did you dig deeper?
  • Ally
    Ally over 2 years
    @LeonardoSibela sorry for that, what I meant to say is adding the --stacktrace option when building so I can get more information on the error.
  • moyo
    moyo over 2 years
    I don't understand why Android Studio does not show the error directly when a build fails, it makes no sense. Thanks for this, helped me a lot
  • Amber
    Amber over 2 years
    You can add the --stacktrace option from File->Settings->Build,Execution,Deployment->Compiler->Comman‌​d-line Options Btw in my case I was missing a dependency: implementation "androidx.room:room-ktx:$room_version"
  • Idan Damri
    Idan Damri about 2 years
    if you have a compile-time Room (DB) error it will show it like that - that means that one or some of your queries is wrong
  • Ishaan Kumar
    Ishaan Kumar about 2 years
    In my case, I forgot to add @Dao in MyDao interface
  • user25
    user25 about 2 years
    amazing, it's helped
  • user25
    user25 about 2 years
    gradle->app->Tasks->Build->assemble what is that?
  • Ajay J G
    Ajay J G about 2 years
    @user25 Gradle tool window
  • Eric
    Eric about 2 years
    I guess it will show like this for any compile-time DB error...in my case, it was a compile-time Realm DB error about a wrongly set up entity object...
  • Daniel Wilson
    Daniel Wilson about 2 years
    Judging by the upvotes, the UI decision here is not a good one
  • Mark Lapasa
    Mark Lapasa about 2 years
    thx for this. I switched it to use 'annotationProcessor' and it successfully built. Then I switched it back to 'kapt' and it was able to build again.
  • varotariya vajsi
    varotariya vajsi about 2 years
    in my case i have forgot to give @PrimaryKey to one of my class
  • Arbaz.in
    Arbaz.in almost 2 years
    What about the realm, i don't know why after updating realm dependency i was getting errors Execution failed for task ':app:kaptJambodevDebugKotlin'. like this ,any solution for same?
  • gMale
    gMale almost 2 years
    Note that the error info will not be in the stacktrace. Instead, when you add the --stacktrace flag the error info shows up right above FAILURE: Build completed with N failures. It took me a second to realize that the room messages were there.
  • BrandonRG
    BrandonRG almost 2 years
    Thank you so mucho bro. This help me.
  • Ajay J G
    Ajay J G almost 2 years
    Assemble will build your artifacts, in other words, assembles the outputs of the project but doesn't build. Build = Assemble + check.
  • Deepak Borade
    Deepak Borade almost 2 years
    great bro.you save my time
  • nyxee
    nyxee over 1 year
    This worked for me. It is never mentioned in the Documentation. So, the set() and notifyPropertyChanged() methods are no longer required??
  • Arst
    Arst over 1 year
    Thank you! Very helpful.
  • Sunkas
    Sunkas over 1 year
    Only useful answer here as problem can vary!
  • Lilia
    Lilia over 1 year
    with annotationProcessor, the error was pretty clear. Thank you
  • Lilia
    Lilia over 1 year
    If you don't see any explanation in that part, you should change the gradle implementation to: implementation "androidx.room:room-runtime:$room" implementation "androidx.room:room-ktx:$room" kapt "androidx.room:room-compiler:$room" androidTestImplementation "androidx.room:room-testing:$room"
  • Mahmoud Mabrok
    Mahmoud Mabrok over 1 year
    I am using same version, and with new update it does not work anymore.
  • Slion
    Slion over 1 year
    I still don't get it…
  • Naimul Kabir
    Naimul Kabir over 1 year
    Thanks a lot, man. I was facing the issue, as I didn't add @Dao annotation in my Dao abstract class.
  • Elliot Schrock
    Elliot Schrock over 1 year
    Had this problem on an old project after updating to AS v4.1.1 and gradle 6.5 (I believe that's the gradle version). Following this answer and updating room deps from 1.0.0 to 2.3.0 worked for me.
  • Waqas ali
    Waqas ali over 1 year
    Bravo! totally save the day
  • Ahmad Salman
    Ahmad Salman over 1 year
    The best answer to the question is this one. there is no one answer to the question a lot could happen so inspect code is the best solution so far.
  • Sathish
    Sathish over 1 year
    Being all setup and annotations correctly i.e Room setup and annotations still faced this issue kaptExecution failure. This solution save me!
  • Edgar
    Edgar over 1 year
    I am getting the same error what is your suggestion
  • Qadir Hussain
    Qadir Hussain about 1 year
    @NaimulKabir thanks. I was missing that too damn Dao. wasted almost 2 hours
  • Peter Nied
    Peter Nied about 1 year
    This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
  • fabio.sang
    fabio.sang about 1 year
    In my case, I had a @TypeConverter from Long to Date but I eliminated the one from Date to Long
  • Nicolas Mage
    Nicolas Mage about 1 year
    Thanks. good workaround to get some funky versions to play nice together.
  • Atif AbbAsi
    Atif AbbAsi about 1 year
    thanks, it worked for me. but now getting the default launcher class does not exist.
  • Kishan Solanki
    Kishan Solanki about 1 year
    Ok. Then what's the solution?
  • Pradeep Singh
    Pradeep Singh about 1 year
    This worked for me ./gradlew clean assembleDebug --stacktrace
  • Yasir Ali about 1 year
    after an hour my project working with this fix. thanks
  • Ajay P. Prajapati
    Ajay P. Prajapati about 1 year
    This isn't the correct answer because you must use kapt now. What solved problem for me is to update android studio gradle build tools and gradle version. It fixed the issue for me and kept kapt
  • Chris Nevill
    Chris Nevill about 1 year
    This gives me the warning : app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'androidx.room:room-compiler:2.3.0'. WARNING: The specified Android SDK Bu
  • Chris Nevill
    Chris Nevill about 1 year
    I think if you look here you still need the kapt - or possibly now alternatively the ksp line: developer.android.com/training/data-storage/room#kts
  • Trevor Gowing
    Trevor Gowing 12 months
    Adding --stacktrace to my Gradle command did the trick. Thanks, @Etienne.
  • shubham chouhan
    shubham chouhan 11 months
    Gave me direction, thanks, just updating room version to 2.4.0-alpha03 worked for me
  • MatJB
    MatJB 11 months
    Not exactly the same error, but this solved my problem after adding Hilt to my project. The error I had was: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$‌​KaptExecutionWorkAct‌​ion > java.lang.reflect.InvocationTargetException (no error message)
  • Hashir Ali
    Hashir Ali 11 months
    This resolved my issue!
  • btraas
    btraas 11 months
    Thank you. Downgrading to 2.3 made it work for now...
  • Ali Salehi
    Ali Salehi 10 months
    finally after a week, I found the solution! thanks man
  • Adnan Bal
    Adnan Bal 10 months
    For Apple M1 users : This solution is for you!.
  • antaki93
    antaki93 9 months
    Can you explain in detail, please?
  • Adrian Sicaru
    Adrian Sicaru 9 months
    I know I am a bit late to the party, but I have a similar problem. And I don't know how to switch to annotationProcessor from kapt.
  • Kyriakos Georgiopoulos 9 months
    At least you will find out what is the error with the DI
  • Mahmoud Mabrok
    Mahmoud Mabrok 8 months
    for new ones. @AjayJG was meant at gradle side menu form IDE open app then tasks
  • mustafa hasria
    mustafa hasria 7 months
    The solution for the M1 chip worked perfectly with me too Thanks