368

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
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Shubham Tater
  • 3,718
  • 2
  • 13
  • 10
  • please show your code in `build.gradle` file. – Sergio Jun 01 '20 at 14:12
  • please show DataBinderMapperImpl.java code as well. – Sergio Jun 02 '20 at 19:26
  • 3
    Have you updated to Android Studio 4? same pb here – Samuel Eminet Jun 03 '20 at 23:19
  • 2
    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. – Hani Jun 04 '20 at 03:17
  • 1
    I had a similar error and found a solution that works for me. You might have done something similar. https://stackoverflow.com/questions/63133657/after-adding-kapt-plugin-a-failure-occurred-while-executing-org-jetbrains-kotl/63139756#63139756 – Mustaqode Jul 28 '20 at 17:35
  • I'm getting this error after migrating to AndroidX – Nagaraj Alagusundaram Sep 08 '20 at 00:29
  • There might be many reasons since error message is not explicit. Mine was make an @Inject field private with dagger-hilt. – Achraf Amil Sep 20 '20 at 12:00
  • for me it was the primary constructor in one database entry class – Dan Alboteanu Aug 18 '20 at 10:46
  • i am facing the same issue for realm any solution ? – Arbaz.in Jan 25 '21 at 12:44
  • 1
    [Moshi 1.12.0 causes this error with Kotlin 1.6.+](https://github.com/square/moshi/issues/1368) Update moshi to 1.13.0 – solidogen Feb 06 '22 at 20:06
  • @solidogen Your moshi-comment solved my problem, you should add it as an answer (there is another moshi-answer, but it "upgrades" to 1.11.0 whereas the current 1.14.0 solves the problem). – arne.jans Jun 16 '23 at 11:49

60 Answers60

456

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

Eric
  • 16,397
  • 8
  • 68
  • 76
  • 23
    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 – Idan Damri Oct 03 '20 at 06:42
  • 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... – Eric Nov 17 '20 at 18:07
  • 29
    Judging by the upvotes, the UI decision here is not a good one – Daniel Wilson Nov 23 '20 at 16:20
  • 3
    Only useful answer here as problem can vary! – Sunkas Apr 23 '21 at 11:55
  • 1
    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"` – Lilia May 04 '21 at 16:58
  • 2
    Thanks a lot, man. I was facing the issue, as I didn't add @Dao annotation in my Dao abstract class. – Naimul Kabir May 20 '21 at 05:37
  • 2
    @NaimulKabir thanks. I was missing that too damn Dao. wasted almost 2 hours – Qadir Hussain Oct 01 '21 at 19:15
111

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

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Ashir Mehmood
  • 1,241
  • 1
  • 8
  • 10
105

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"
tuanvn91
  • 1,159
  • 1
  • 6
  • 8
102

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

./gradlew assembleDebug --stacktrace
Etienne Lawlor
  • 6,817
  • 18
  • 77
  • 89
49

Click on --stacktrace on the terminal to see the error in details. You can find it here:

enter image description here

M1 Chip Solution

If you have a MacBook Pro chances are that adding kapt "org.xerial:sqlite-jdbc:3.34.0" before the room-compiler will solve your problem.

  kapt "org.xerial:sqlite-jdbc:3.36.0" // Only for computer with M1 CPU
  implementation("androidx.room:room-ktx:$room_version")
  kapt "androidx.room:room-compiler:$room_version"

See more here.

Mattia Ferigutti
  • 2,608
  • 1
  • 18
  • 22
41

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

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53
31

I got the same issue, so I tried to get more information, by doing

gradle->app->Tasks->Build->assemble

After this I got exact error saying "Error while annotation processing". I checked my recently tweaked DAO class and found that one of the method return type was not defined.

//Before
@Query("SELECT countryName FROM country_table WHERE countryCode= :code")
    fun getCountryNameForCode(code: String)

//After
@Query("SELECT countryName FROM country_table WHERE countryCode= :code")
    fun getCountryNameForCode(code: String): String
Ajay J G
  • 886
  • 7
  • 21
25

After a lot of pain, I decided to try annotationProcessor instead of kapt hoping it may at least show an error message or anything that can help me locate the source. But fortunately (or unfortunately; because of the wasted time), it was built successfully without any errors. It's mostly a bug in kapt itself. So, try this solution and it may help.

Salih Kavaf
  • 897
  • 9
  • 17
  • 2
    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. – Mark Lapasa Nov 26 '20 at 22:17
  • 1
    with `annotationProcessor`, the error was pretty clear. Thank you – Lilia Apr 30 '21 at 16:41
  • This resolved my issue! – Hashir Ali Feb 03 '22 at 20:54
  • 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. – Adrian Sicaru Apr 06 '22 at 15:44
  • @AdrianSicaru find strings starts with "kapt 'your_dependency_name:X.Y.Z" in your build.gradle file and replace it to "annotationProcessor 'your_dependency_name:X.Y.Z" – antaki93 Dec 03 '22 at 22:00
21

I had the same error for a while then I started checking the other packages I came to know that I've made a typo mistake in my database code. So, "Go through your database and other activity class files u may find some mistakes there."

Aman Srivastava
  • 1,007
  • 1
  • 13
  • 25
ShankarAnand
  • 254
  • 1
  • 8
13

Okay, this issue also occurs if you are using Android Studio 4.1.2.

So, what you have to do is:

  • Download jdk 11 (Search and download)

  • In Android Studio, go to File -> Project Structure -> Jdk Location -> Change to the path of the Jdk you just downloaded.

Ibramazin
  • 958
  • 10
  • 30
12

For me, a bunch of reference errors and an error in the XML expressions with DataBinding produced this error.

I have deleted a <variable/> in a layout file, because I thought, I don't need it anymore. I forgot that I had the variable referenced in the layout file.

After building the project, this produced an error, where it was not possible to import the BindingImpl class, because it does not exist and this error was only shown as a warning parallel to the above KaptExecution error.

After searching for a while, I found this error and resolved it. Then, a bunch of reference errors where shown, because I renamed something and it did not rename it in the Fragment files. After resolving these errors too, the build finished for me without errors or warnings.

René Jörg Spies
  • 1,544
  • 1
  • 10
  • 29
11

try to build your project with

kapt.use.worker.api=false 

in your gradle.properties settings file

Reference: https://youtrack.jetbrains.com/issue/KT-40750

AndroidSam27
  • 238
  • 2
  • 11
  • Being all setup and annotations correctly i.e Room setup and annotations still faced this issue kaptExecution failure. This solution save me! – Sathish Jul 04 '21 at 17:14
9

The same problem for me here. In my case, the reason is that I've forgot a @Module annotation in one of my dagger module.

To find the real problem of such an AS alert, it's necessary going deep: the messagge in the title it's only the final one, the 1 or more causes of the error are shown selecting the root element on the left, that shows you the exact problems, check my printscreen below :

in  details final message

android_dev71
  • 517
  • 5
  • 7
7

I had the same problem. In my case the problem was about Database. i had to change this line of code @Database(entities = [SearchedLocation::class, FavoriteLocation::class], version = 1)

I added another table in Database but forgot to add table in the line above.

7

In my case I forget adding @PrimaryKey in Entity class.

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
Ahmet B.
  • 1,290
  • 10
  • 20
  • 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? – Arbaz.in Jan 25 '21 at 12:46
6

I had the same problem. Let me walk you through the example on how I ended up to the problem and the way I resolved it perhaps you can get a bigger picture.

Before resolving

@Entity(tableName = "modules")
data class Module
(
    @PrimaryKey val id: Int,
    val name: String
)

@Entity(tableName = "sessions")
data class Session
(
    @PrimaryKey(autoGenerate = true) var id: Int,
    @ColumnInfo(name = "module_id") val moduleId: Int,
    @ColumnInfo(name = "start_time") val startTime: String,
    @ColumnInfo(name = "end_time") val endTime: String
)

data class ModuleSession
(
    @Embedded val module: Module,
    @Relation(
        parentColumn = "id",
        entityColumn = "module_id"
    )
    val sessions: List<Session>,
    @ColumnInfo(name = "is_updated") val isUpdated: Boolean = false // The problem
)

In the DAO

@Transaction
@Query("SELECT * FROM modules")
abstract suspend fun getModuleSession(): List<ModuleSession>

The error I got was

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

So I dug deeper and found the below message

The columns returned by the query does not have the fields [isUpdated] in com.gmanix.oncampusprototype.Persistence.ModuleSession even though they are annotated as non-null or primitive. Columns returned by the query: [id,name]
    public abstract java.lang.Object getModuleSession(@org.jetbrains.annotations.NotNull()

I removed the field IsUpdated from the POJO ModuleSession and added it to the session table

After changes

@Entity(tableName = "sessions")
data class Session
(
    @PrimaryKey(autoGenerate = true) var id: Int,
    @ColumnInfo(name = "module_id") val moduleId: Int,
    @ColumnInfo(name = "start_time") val startTime: String,
    @ColumnInfo(name = "end_time") val endTime: String,
    @ColumnInfo(name = "is_updated") val isUpdated: Boolean = false
)

data class ModuleSession
(
    @Embedded val module: Module,
    @Relation(
        parentColumn = "id",
        entityColumn = "module_id"
    )
    val sessions: List<Session>
)

On the other hand crosscheck if there is any field on the SELECT statement that is a suspect causing issues or you can annotate it with @Ignore

However you can post your code if you're still not comfortable.

I hope that might help

Ally
  • 783
  • 6
  • 14
  • 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 Jun 24 '20 at 02:43
  • 2
    Yes please. how did you dig deeper? – Simo Nyathi Aug 06 '20 at 08:50
  • 2
    @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. – Ally Aug 09 '20 at 14:22
  • 1
    You can add the --stacktrace option from File->Settings->Build,Execution,Deployment->Compiler->Command-line Options Btw in my case I was missing a dependency: implementation "androidx.room:room-ktx:$room_version" – Amber Aug 30 '20 at 21:24
  • 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_. – gMale Jan 28 '21 at 04:19
5

If you have upgraded to classpath 'com.android.tools.build:gradle:4.0.0' Replace it previous version

dependencies {
    classpath 'com.android.tools.build:gradle:3.6.3'
}

And Change gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-   all.zip`
Mujeeb Rahaman T
  • 448
  • 3
  • 13
5

I got the same problem when I added ROOM to my App(Kotlin). I had a hard time finding out what was wrong and finally figured out that i was using the following for adding ROOM to my app.

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

So i changed the above two lines with the following and got rid of the pain.

    def room_version = "2.2.6"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

Hit the up button if it helped you :D

Nasib
  • 1,173
  • 1
  • 13
  • 23
5

In my case I got this error when moving from jcenter() to mavenCentral(), one of my dependencies was available only on jcenter() and not mavenCentral(). So i submitted issue to the owner for the same on github and will wait to remove jcenter() until its moved.

Dashesh
  • 308
  • 3
  • 11
4

In my case, I used room and one of my databasDao methods has an unused parameter and unfortunately android studio doesn't warn me correctly

Vahid
  • 1,588
  • 4
  • 22
  • 34
4

This problem also happens if you installed new kotlin plugin (1.4.20-release-Studio4.1-1) and have dagger (kapt 'com.google.dagger:dagger-compiler:2.30'). In such a case one solution might be replacing deprecated plugin: 'kotlin-android-extensions' with view binding (https://developer.android.com/topic/libraries/view-binding)

Kairat
  • 698
  • 1
  • 11
  • 14
4

Looks like there is an issue with room library and apple M1 chips.

Update your room lib version to 2.4.0-alpha03 or above and resync project.

Worked for me!

shubham chouhan
  • 580
  • 7
  • 8
4

In my case there were older dependencies which needed an upgradation, So you can follow this :

1.FILE -> PROJECT STRUCTURE ->

enter image description here

2.Go to SUGGESSIONS ->

3.Under the WARNING SECTION Android Studio will show you which dependencies needs to be upgraded->

4.Just upgrade it directly from there ->

5.CLICK APPLY->

It will work now!

Thanks!

3

I just had this happen to me. Another dev had not completed a merge properly so this line was in the code

<<<<<<< HEAD

Instead of getting a compile error I got the KaptExecution error.

Kevin
  • 1,405
  • 15
  • 16
3

In my case I was using Coroutines but I forget to add Kotlin Extensions and Coroutines support for Room

def room_version = "2.2.6" implementation "androidx.room:room-ktx:$room_version"

mahmood
  • 369
  • 3
  • 8
3

In my case adding new fragments always resulted in this error popping up, I investigated my commit changes on git and it turns out that Android keeps auto-updating the gradle plugin whenever I create a new Fragment despite not giving it permissions to do so, so I had to rollback to my original gradle-plugin version inside the project level's build.gradle file:

from

classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0'

to

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"

Monitor your git changes to figure out what Android is doing to your gradle files that's causing it to crash.

M.Ed
  • 969
  • 10
  • 12
2

Shout Out to @Rene Spies' answer above, I also got this error while working with databinding. It turns out the build engine doesn't like it when you put the @Bindable annotation on a field in the primary constructor of a data class in Kotlin.

So never do the following,

data class MyAwesomePojo(
    @Bindable
    var firstname: String,
    var lastname: String
)

instead what you need to do is

data class MyCorrectAwesomePojo(
    var lastname: String
):{
    @get:Bindable
    var firstname: String
        set(value){
            field = value
        }
}

Bonus: remember to check for same values before setting value to field if you are trying to use two-way binding like me to prevent infinite looping of setting and getting.

EAM
  • 361
  • 2
  • 5
  • 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 Jun 24 '20 at 02:43
2

In my case it was because I was not implementing Observable in my ViewModel. I added an EditText to the constraint layout with android:text="@={addProductViewModel.inputProductName}"

Once I implemented Observable in my ViewModel class the error was gone

ViewModel

class AddProductViewModel (
    private val repository: ProductRepository,
    private val context: Context
): ViewModel(), Observable {

    @Bindable
    val inputProductName = MutableLiveData<String>()


    fun addProduct() {
        //inputProductName.value
    }

    override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
        TODO("Not yet implemented")
    }

    override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
        TODO("Not yet implemented")
    }
}

Complete example for MVVM Databinding using Fragments

Layout - add_product.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <data class=".AddProductBinding">
        <variable
            name="addProductViewModel"
            type="com.rao.iremind.AddProductViewModel" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <EditText
            android:id="@+id/editTextTextProductName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Product name"
            android:inputType="textPersonName"
            android:text="@={addProductViewModel.inputProductName}"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />



    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

AddProductFragment

class AddProductFragment: Fragment() {
    private lateinit var binding: AddProductBinding
    private lateinit var addProductViewModel: AddProductViewModel
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding =  DataBindingUtil.inflate(inflater, R.layout.add_product, container, false)
        val dao = SubscriberDatabase.getInstance(requireActivity().applicationContext).productDAO
        val repository = ProductRepository(dao)
        val factory = AddProductViewModelFactory(repository, requireActivity().applicationContext)
        addProductViewModel = ViewModelProvider(this, factory).get(AddProductViewModel::class.java)
        binding.addProductViewModel = addProductViewModel
        binding.lifecycleOwner = this
        val view = binding.root

        return view
    }
}

AddProductViewModel

class AddProductViewModel (
    private val repository: ProductRepository,
    private val context: Context
): ViewModel(), Observable {

    @Bindable
    val inputProductName = MutableLiveData<String>()


    fun addProduct() {
        //inputProductName.value
    }

    override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
        TODO("Not yet implemented")
    }

    override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
        TODO("Not yet implemented")
    }
}

Hope this helps R

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • This worked for me. It is never mentioned in the Documentation. So, the set() and notifyPropertyChanged() methods are no longer required?? – nyxee Mar 26 '21 at 23:25
2

In My Case: Issue resolved

Steps:

  1. Remove viewModel variable - In XML.
<variable
    name="viewModel"
    type="com.xx.AppViewModel" / >
  1. Removed all viewModel binding references - In XML.
android:text="@{viewModel.simName}"
  1. Removed viewModel instance reference to the binding mapping - In Activity
binding.viewModel = viewModel
  1. Clean project and recompile.

  2. Add viewModel variable - In XML & Build project.

< variable
    name="viewModel"
    type="com.xx.AppViewModel" / >
  1. Add viewModel instance reference to the binding mapping - In Activity & Build project
binding.viewModel = viewModel
  1. Add all viewModel binding references - In XML & Build project..
    android:text="@{viewModel.simName}"
  1. It will work now.

-- I hope it will work for you also.

Anbuselvan Rocky
  • 606
  • 6
  • 22
2

I had same problem with Room and i was not using viewBinding.
I Fixed it with using exportSchema to false in my database class.

@Database(entities = [ModelClass::class], version = 1, exportSchema = false)
abstract class ModelDatabase: RoomDatabase() {}

Remember: exportScehma could be vary according to your use case, generally it stays false so i put it to false.

USMAN osman
  • 952
  • 7
  • 13
2

In my case I have changed globally one variable UserManager to NetWorkManager and everywhere where there were UserManager classes they turned to be NetworkManager.

Because I'm using Hilt, I had to build the project again.

I cleaned the Project and Kotlin showed where the errors were.

Dimitri Leite
  • 1,791
  • 13
  • 16
  • 1
    Had the same error pop up with Dagger-Hilt. Rebuilding, cleaning, invalidating cache, etc didn't fix it. Rolling back `'org.jetbrains.kotlin:kotlin-gradle-plugin:VERSION_NUMBER'` in project's build.gradle file from `1.7.0` to `1.6.21` fixed it. – M.Ed Jul 13 '22 at 15:16
2

For me, the issue was with having 2 primary keys defined on the model.

// before    
@field:ColumnInfo(name = "id") @field:PrimaryKey(autoGenerate = true) var id: Long = 0,
@field:ColumnInfo(name = "name") @field:PrimaryKey var name: String,
    
//after
@field:ColumnInfo(name = "id") @field:PrimaryKey(autoGenerate = true) var id: Long = 0,
@field:ColumnInfo(name = "name") @field:NotNull var name: String,

I had to rebuild the project and change the Dao class a little bit to trigger the message about the issue.

2

I had the same error. I had two issues.

  1. You may need to add

    implementation 'androidx.room:room-ktx:2.2.5'

  2. I had deleted a file that was referenced as a member in one of the activity_xml files. The error never gave me any clue until I changed it to annotationProcessor instead of kapt, then it pointed out the error, I found the file, and sure enough I had a reference to a file that I no longer used and was deleted. I removed this data reference from the xml and it cleared it all up. Then I put it back to kapt.

Sam
  • 5,342
  • 1
  • 23
  • 39
2

In my case downgrading the kotlin version ( from 1.4.21 to 1.3.21) solved my issue .

    buildscript { 
    ext.kotlin_version = '1.3.21'

    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
}
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
RANAJEET BARIK
  • 185
  • 2
  • 7
2

If you are using Kotlin with Hilt

Make sure you have annotated your module class with

@Module
@InstallIn(SingletonComponent::class)
class AppModule {
//...
}
Thiago
  • 12,778
  • 14
  • 93
  • 110
1

Interestingly, I was getting this error because I added the description of the Retrofit. Be careful not to confuse the description of Room and Retrofit.

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
1

in my case, I have added this line

 android {
    .
    .
    .

    kapt.includeCompileClasspath = false

 }
Mojtaba Haddadi
  • 1,346
  • 16
  • 26
1

I was also encountered with the same problem so for just try I deleted it project's .idea folder and .gradle folder then i also deleted build folder inside app folder and then restart android studio IDE and it works for me

Fahd Tahir
  • 55
  • 5
1

This method occurs to me everything there is a problem with Room database and Coroutines, even spell mistakes. Lastly was when trying to return a single value with a Flow after inserted column, by: Flow<Long> from DAOs classes.

It should be a suspend function and only Long type to return after inserted column.

These problems are ambiguous sometime, so try to read all the Build Output messages, the message that help me was: error: Not sure how to handle insert method's return type.

MohammadL
  • 2,398
  • 1
  • 19
  • 36
1

Nothing worked I tried everything and finally found a small mistake which was creating a big problem.

Go back to each newly created file for database and check for code line by line of each file carefully.

Check Database class and check if Dao is declared as for example,

abstract val commentDatabaseDao: CommentDatabaseDao

declare as val not var, this was in my case and finally for this resolved.

Sachin Harne
  • 175
  • 2
  • 14
1

I just updated Android Studio IDE to 4.1.1 version and got a similar issue.

What I realised was…

… before I did not had some *_Impl classes (I know about them in Kotlin stuff) and not even some new *Tests classes.

So, after “run all the World” to take a solution, I just made an intuitive and fair choice: I deleted all those files inside my "hand builded" packages that was not there before Android Studio update.

And, guess what?

It worked. No issues, not even one problem about kapt.

I’m not saying that it is a final solution. But it can work for you.

Have a good one.

Thiengo
  • 226
  • 1
  • 3
  • 33
1

Yup, I also got this error and it was also a Room related issue.

I had defined my TypeConverters, but never annotated my Room database with: @TypeConverters(TypeConverter.class).

Izak
  • 909
  • 9
  • 24
1

It's can be happened if non-english characters used in binding expressions within layout. For example:

<TextView ... android:text="@{ viewModel.letterTitle, default=`Важное письмо` }" />

You can check this case if you execute "Run with --stacktrace option". If stacktrace contains message "MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence." then possibly

  • layout contains non-english characters
  • or some source xml file have incorrect format
Evgeniy Mironov
  • 777
  • 6
  • 22
1

Solved by just increasing gradle version to latest -

It is in the project level gradle file, under dependencies block.

classpath "com.android.tools.build:gradle:4.x.x"
Prateek Sharma
  • 312
  • 3
  • 5
1

This happened to me when trying to Inject a private field inside an activity using Hilt.the solution was to remove the private keyword so change

@Inject
private lateinit var appAnalytics: AppAnalytics

to

@Inject
lateinit var appAnalytics: AppAnalytics
Mohammed Fathi
  • 1,237
  • 1
  • 14
  • 12
1

For me, this issue occurred because of the java version difference
In my case
-My studio default java version was 11
-I have a library in my project with java version 8 support

Fix -
1.listed all installed java version with command /usr/libexec/java_home -V
2.Copy java8 path:/Library/Java/JavaVirtualMachines/1.8.0_232.jdk/Contents/Home
3. go to File - Project structure - SDK location -JDK location
Add your java path there

Libin Thomas
  • 1,132
  • 13
  • 17
1

it took me days to find the solution to this problem, use a high version of the androidx.lifecycle:lifecycle-compiler plugin.

implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0-alpha03'

kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0-alpha03'

and remove this from your code kapt "android.arch.lifecycle:compiler:1.1.1"

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/29974683) – Peter Nied Oct 02 '21 at 17:06
1

For me the problem is about kotlin gradle plugin. Sometimes android studio updates kotlin gradle plugin by itself. Revert back gradle plugin solves problem.

For insatance from this:

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"

to this:

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
Cembora
  • 244
  • 2
  • 15
1

Check the compatible version of kotlin and hilt

yusufgltc
  • 51
  • 5
0

in some cases it may help gradle.properties

kapt.include.compile.classpath=true
Sergei Maleev
  • 307
  • 3
  • 4
0

Got exactly the same error while upgrading to kotlin_version = '1.4.31' (from 1.3.71)

The following moshi upgrade fixed the my problem:

implementation("com.squareup.moshi:moshi:1.11.0")
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.11.0")
Sean
  • 2,967
  • 2
  • 29
  • 39
0

I have an enum in my entity property using ROOM. It causes the following failure after long searching.

Execution failed for task ':app:kaptDebugKotlin'.

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

enum class Color{RED,BLACK,BLUE,GREEN,WHITE}
@Entity(tableName = "flower_table")
data class Flower(
        @PrimaryKey(autoGenerate = true) val id: Int,
        @ColumnInfo(name = "name") val name: String,
        @ColumnInfo(name = "color") val color: Color)

val flower = Flower(2, "rose", Color.RED)

My solution is to use the index of the enum instead in the entity property.

@Entity(tableName = "flower_table")
data class Flower(
        @PrimaryKey(autoGenerate = true) val id: Int,
        @ColumnInfo(name = "name") val name: String,
        @ColumnInfo(name = "color") val color: Int)

val flower = Flower(4, "tulip", Color.BLUE.ordinal)

I hope it could help you! PS, do not forget to update the version number in your database class.

@Database(entities = [Flower::class], version = 2)
abstract class FlowerRoomDatabase : RoomDatabase() {
Diiiiii
  • 209
  • 3
  • 8
0

I was getting the same error, and for me the issue was I needed to switch from Gradle JDK JDK version 16.0.1 to Android Studio java home version 11.0.10 in Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle

stephenspann
  • 1,823
  • 1
  • 16
  • 31
  • 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$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message) – MatJB Jan 21 '22 at 12:47
0

I got this error after doing the following:

  1. Upgrading Android Studio to Arctic Fox
  2. Updating the Kotlin plugin to version 1.5.21
  3. Upgrading my Java version to 16

Running assembleDebug with --stacktrace, I saw this exception in the logs: Caused by: java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext. Searching around, I found this link that talks about compatibility issues between kapt and JDK16+.

I resolved the issue by making this change in my gradle.properties file: org.gradle.jvmargs=-Xmx1536m --illegal-access=permit

srinij
  • 471
  • 6
  • 10
0

This error also comes due to data binding errors

  1. Check if your variable is pointing to the correct data class
  2. Check if your fields due for your views (text view, visibility are correct)
  3. You have imported the correct imports (for eg for visibility related operations)
Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
0

In my case I just renamed rootProject.name in /settings.gradle I repeated this action again and it works .. It doesn't make sense why it happened but I hope that may help others and save their time

Maher Abuthraa
  • 17,493
  • 11
  • 81
  • 103
0

In my case i solve it by updating my kotlin version from 1.3.x to 1.6.0.

0

This answer would be useful for those who switch from one account(user) to another user on same machine (WINDOWS OS)

I faced similar issue

failure occurred while executing org.jetbrains.kotlin.gradle.internal.kaptwithoutkotlinctask

But the reason was permission denied for the below file

C:\Android\.gradle\caches\modules-2\files-2.1\com.android.tools.build.jetifier\jetifier-core\1.0.0-beta09\c98ee0e5579aed97e17f605a89b101115a2f5a61\jetifier-core-1.0.0-beta09.jar

The issue scenario

What I did was, copied C:\Android.gradle\ from my previous machine to the new machine. The user account I used on new machine was say X. I created a new account and then deleted the account X.

Since X was the owner, the new account had issues with permission.

The solution is to change ownership or delete the C:\Android.gradle\ and let Android Studio(AS) download the same. I faced the ownership issue while commit as well for the same reason. To avoid any further issue, I deleted C:\Android (which included .gradle, .android, C:\Android\Local\Android\Sdk folders ) reinstalled Android Studio.

git submodule update failed with 'fatal: detected dubious ownership in repository at'

tanni tanna
  • 544
  • 4
  • 12
0

If somebody is facing this error due to adding test dependencies for hilt (which was the reason i faced this error) Make sure you have same version for both normal and test dependencies

// Hilt Dependency
implementation 'com.google.dagger:hilt-android:2.38.1' kapt 'com.google.dagger:hilt-compiler:2.38.1'

//Hilt for testing
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.38.1' kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.38.1'

0

Go under Settings | Preferences | Build, Execution, Deployment | Build Tools | Gradle and set Gradle JDK value to Embedded JDK. It will do wonders :)

enter image description here

tGitm
  • 45
  • 8