A failure occurred while executing org.jetbrains.k

2020-07-02 22:17发布

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

7条回答
叛逆
2楼-- · 2020-07-02 23:00

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.

查看更多
时光不老,我们不散
3楼-- · 2020-07-02 22:36

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.

查看更多
可以哭但决不认输i
4楼-- · 2020-07-02 22:38

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
查看更多
闹够了就滚
5楼-- · 2020-07-02 22:41

Change

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

To

 implementation "androidx.room:room-runtime:2.2.5"
 kapt  "androidx.room:room-compiler:2.2.5"
查看更多
Animai°情兽
6楼-- · 2020-07-02 22:44

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`
查看更多
Animai°情兽
7楼-- · 2020-07-02 22:50

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

查看更多
登录 后发表回答