11

First of all,

I'm pretty much aware that a lot of questions on this error had been posted already here, and none of them seems to be having a proper solution especially the one I need.

I'm stuck with the following error for over a week.

I'm working on an android project which is being built using Kotlin, MVVM, Clean Arch, and Navigation Components.

I recently added realm database, and for that I had to add the following plugins.

apply plugin: 'kotlin-kapt'

apply plugin: 'realm-android'

The real problem started from here I think.

(After that I added a DatabaseManager class which makes use of some realm extension functions I wrote to make db operations.)

When I compile the project after this, the following error occurred overall.

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

Along with the following

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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 7s
30 actionable tasks: 6 executed, 24 up-to-date

It points to my MainActivity class which is unaltered and doesn't seem to have any errors or typos for that matter. I'm pretty much sure that the kapt annotation processor does some dirty job here that I do not seem to figure out.

enter image description here

I will be greatly relieved if I could get past this weird error.

Additional note:

  1. I have separated my entire project into three modules. All three got kapt plugin (just incase)

  2. I use Koin for DI

Hope someone will help me out!

Mustaqode
  • 453
  • 1
  • 4
  • 14

11 Answers11

11

Replacing

kapt "android.arch.persistence.room:compiler:$room_version"

by

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

might fix it as well.

Marcus Runge
  • 635
  • 6
  • 17
5

I had the same problem. I forgot to add @Dao annotation in my room database

iknow
  • 8,358
  • 12
  • 41
  • 68
Javad Shirkhani
  • 343
  • 6
  • 11
4

After a week's struggle, I finally found the issue.

I added the kotlin-kapt plugin for realm.

And I had a folder named interface itself to hold some interfaces.

I implemented one of the interfaces from the interface folder in MainActivity.

Now the import for the interface was something like this,

import com.android.app.java.interface.Listener

Where, the keyword interface confused the annotation processor, hence caused error while generating stub.

I renamed the folder (from interface to intrface).

That solved the error.

This is a very simple mistake that cost me a week.

Anyway, found the issue. Yay!

Mustaqode
  • 453
  • 1
  • 4
  • 14
3

I had the same problem because i had forgotten to add a converter in a list included in entity..In room you have to add converters in order to store lists in databas

john21
  • 29
  • 1
  • 4
  • Actually this is important point nobody can notice it, I had this problem and searched a lot until I found this answer.. thanks bro – M.Fakhri Nov 12 '20 at 17:06
2

I had a similar issue and spent forever trying to find the issue. I found another thread that you can run Analyze -> Inspect Code to find the issue, but this didn't work for me and showed nothing, but apparently others had success with this.

My issue ended up being with my database (I was using Room) and the fix was simply a matter of removing a "suspend" I had on an insert function in my DAO..

I found this issue by looking in the java generated code folder. Look at all your database files that are generated with "_Impl". The error was highlighted in red and then I could deduce from here what was going wrong (although I don't know why Android Studio couldn't just show me that error in the build output :/ )

Best of luck though! Those kapt errors are the worst

Sarah Mica
  • 121
  • 1
  • 7
2

check your fields in Model DB maybe you have val, change to var like this:

open class User(var id: Int?= null,
            var name: String? = null,
            var lastName: String? = null): RealmObject()
Vitalii
  • 21
  • 2
1

I put a @Delete annotation on a method with Long parameters :

@Delete
fun deleteRelationShip(userId: Long, friendId: Long)

--debug build can be of help i most cases. In this case it said that a long couldn't be convert in Element

Then it becomes

@Delete
fun deleteRelationShip(relationShip: RelationShip)
vhflat
  • 561
  • 6
  • 19
0

For me when I rewrited dao class it solved problem

Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78
0

If Room is used in the app, it could be related to some mistakes added in the room related classes. I had same error and took hours to figure out the issue. I had given wrong class name in the entities session of @Database(entities=[...])

png
  • 4,368
  • 7
  • 69
  • 118
0

i had the same problem but wht i did was i update all the dependencies to the latest version, this worked for me

Abili Isaac
  • 574
  • 4
  • 5
0

In my case what helped replacing apply plugin 'kotlin-kapt' to plugins{ id 'kotlin-android' id 'kotlin-kept'} Only commenting apply plugin was enough, still to get rid off warning and kotlin-android-extensions I have to rewrite some code to not use syntetic classes.

SkorpEN
  • 2,491
  • 1
  • 22
  • 28