13

Im working on an Android App, currently using DSL and some libraries, suddenly the build gave me this error.

Task :app:kaptDebugKotlin FAILED ANTLR Tool version 4.7.1 used for code generation does not match the current runtime version 4.5.3ANTLR Runtime version 4.7.1 used for parser compilation does not match the current runtime version 4.5.3 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)

i've been searching but with no success...

If you wanna see the issue you can clone the project. Project GITHUB Im using Android Studio Canary 4.1.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Luis Cardoza Bird
  • 1,265
  • 4
  • 24
  • 43

8 Answers8

3

So the solution was from the build.gradle

basically the import from ROOM was this

import(Room.compiler)

so i changed to this, and the issue was solved :)

kapt(Room.compiler)
Luis Cardoza Bird
  • 1,265
  • 4
  • 24
  • 43
  • 5
    Thanks man you pointed me to the right way and literally saved my programming career ... I was doing a project on the Codelabs and faced a `Execution failed for task ':app:kaptdebugkotlin` error and has been on it stuck for 13 days. You can imagine the headache and helplessness face – Tonnie Apr 01 '20 at 16:59
  • I already have this, so something else is using this and needs a kapt option – JPM Jun 29 '20 at 21:03
  • where should i put that? – Simou Nov 28 '20 at 15:12
  • On your build.gradle inside your app folder, to be precissed on the dependency group – Luis Cardoza Bird Nov 30 '20 at 00:37
3

Inside the build.gradle(Module:app) copypaste this code

enter image description hereconfigurations.all() { resolutionStrategy.force "org.antlr:antlr4-runtime:4.5.3" resolutionStrategy.force "org.antlr:antlr4-tool:4.5.3" }

Tonnie
  • 4,865
  • 3
  • 34
  • 50
2

For anyone still experiencing this issue, just update your Room to the latest version:

androidx.room:room-runtime:2.3.0-alpha04
androidx.room:room-compiler:2.3.0-alpha04

It's due to this bug: https://issuetracker.google.com/issues/155215201

Jim Ovejera
  • 739
  • 6
  • 10
2

The problem was fixed for me by changing this. from:

implementation "androidx.room:room-runtime:$depVersion"
implementation "androidx.room:room-compiler:$depVersion"

to:

implementation "androidx.room:room-runtime:$depVersion"
annotationProcessor "androidx.room:room-compiler:$depVersion"
Tim L.
  • 51
  • 3
1

Removing suspend keyword from queries in DAO interface, solved my problem

Ercan
  • 2,601
  • 22
  • 23
0

I got similar error. I have all files in Java and I changed few files to Kotlin. Then this issue showed up.

I have a function in a Java file accessing static function in a Kotlin file. That's the point where the app crashed.

Code in Kotlin file:

companion object{
    @JvmStatic
    fun myStaticFunction(){
        // body of the static function
    }
}

I added the annotation @JvmStatic(see the above code) to the function and the error got resolved.

This is a very specific scenario in which this crash occurs and may not be applicable to all.

Light Yagami
  • 961
  • 1
  • 9
  • 29
0

At lease for me, the root cause of this problem/error is because of the data binding not being handled properly. Currently, Android Studio does not have a mechanism to show error message for unreferenced variables in .xml file.

For example, In MyViewModel.kt, If I have a property name as,

var email

and you are mapping this property in xml as,

@={model.errEmail}

instead of @={model.email}

You get to see this error.

If you see this error, just go to layout xml file and check the binding names/mappings and correct it.

Karthik H
  • 1,267
  • 12
  • 13
-1

Had a similar issue. I was trying to implement bindingAdapters to a TextView of a ViewHolder in my recyclerview

I failed to implement a bindingAdapter for a TextView after adding the adding a unique app attribute

app:tDate="@{transaction}

in the xml layout file for my recylerView item.

<TextView
        android:id="@+id/trans_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/trans_category"
        app:layout_constraintTop_toTopOf="parent"
        app:tDate="@{transaction}"/>

Solved it by well.. implementing it.

@BindingAdapter("tDate")
fun TextView.setValue(item: Transactions){
    text = item.date.toString()
}