突然我开始得到这个错误,我不知道为什么如果有人告诉我这个错误在哪里,就足够有帮助了。正如我所能得到的,这是因为android studio的新更新。 我得到的错误的详细总结。

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

当前回答

在我的案例中,降低kotlin版本(从1.4.21到1.3.21)解决了我的问题。

    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" }
}

其他回答

这种方法出现在我的一切房间数据库和协程的问题,甚至拼写错误。最后是当试图返回一个带有Flow after inserted列的单个值时,通过:Flow<Long> from DAOs类。

它应该是一个挂起函数,并且在插入列后只返回Long类型。

这些问题有时是模棱两可的,所以尝试阅读所有的构建输出消息,帮助我的消息是:错误:不确定如何处理插入方法的返回类型。

在终端上单击——stacktrace查看错误的详细信息。你可以在这里找到它:

M1芯片解决方案

如果你有一台MacBook Pro,那么在房间编译器之前添加kapt "org. x里尔:sqlite-jdbc:3.34.0"就有可能解决你的问题。

  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"

点击这里查看更多信息。

我有一个枚举在我的实体属性使用房间。经过长时间的搜索,导致如下失败。

“:app:kaptDebugKotlin”任务执行失败。 执行org.jetbrains.kotlin.gradle.internal.KaptExecution时发生失败 invocationtargetexception(没有错误消息)

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)

我的解决方案是在实体属性中使用枚举的索引。

@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)

希望能对你有所帮助! PS,不要忘记更新数据库类中的版本号。

@Database(entities = [Flower::class], version = 2)
abstract class FlowerRoomDatabase : RoomDatabase() {

如果你安装了新的kotlin插件(1.4.20-release-Studio4.1-1)并安装了dagger (kapt 'com.google.dagger:dagger-compiler:2.30'),也会出现这个问题。在这种情况下,一种解决方案可能是用视图绑定替换已弃用的插件:'kotlin-android-extensions' (https://developer.android.com/topic/libraries/view-binding)

以我为例:问题解决了

步骤:

删除viewModel变量-在XML中。

<variable
    name="viewModel"
    type="com.xx.AppViewModel" / >

删除了所有viewModel绑定引用-在XML中。

android:text="@{viewModel.simName}"

删除了对绑定映射- In活动的viewModel实例引用

binding.viewModel = viewModel

清理项目并重新编译。 在XML & Build项目中添加viewModel变量。

< variable
    name="viewModel"
    type="com.xx.AppViewModel" / >

将viewModel实例引用添加到绑定映射-在活动和构建项目中

binding.viewModel = viewModel

添加所有viewModel绑定引用-在XML & Build项目中..

    android:text="@{viewModel.simName}"

它现在可以工作了。

——我希望这对你也有用。