突然我开始得到这个错误,我不知道为什么如果有人告诉我这个错误在哪里,就足够有帮助了。正如我所能得到的,这是因为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

当前回答

以我为例:问题解决了

步骤:

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

它现在可以工作了。

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

其他回答

对我来说,问题是关于kotlin gradle插件。有时候android studio会自己更新kotlin gradle插件。回复gradle插件解决问题。

举个例子:

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

:

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

在我的情况下,我已经将全局一个变量UserManager更改为NetWorkManager,凡是有UserManager类的地方,它们都变成了NetWorkManager。

因为我用的是希尔特,所以我必须重新构建项目。

我清理了项目,Kotlin显示了错误的位置。

如果在布局中的绑定表达式中使用非英语字符,则会发生这种情况。例如:

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

如果执行“带——stacktrace选项运行”,就可以检查这种情况。如果stacktrace包含消息"MalformedByteSequenceException: 2字节UTF-8序列中的2字节无效。

布局包含非英文字符 或者某些源XML文件格式不正确

我也遇到了同样的问题,所以我试图通过做来获得更多的信息

gradle - >应用程序- > - > Build - >组装任务

在这之后,我得到确切的错误说“错误,而注释处理”。 我检查了最近调整的DAO类,发现其中一个方法返回类型没有定义。

//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

如果有人面临这个错误,由于添加测试依赖柄(这是我面临这个错误的原因) 确保正常依赖项和测试依赖项的版本相同

// Hilt Dependency 实现“com.google.dagger: hilt-android: 2.38.1” kapt com.google.dagger: hilt-compiler: 2.38.1

//测试柄 androidTestImplementation com.google.dagger: hilt-android-testing: 2.38.1 kaptAndroidTest com.google.dagger: hilt-android-compiler: 2.38.1