用于代码生成的 ANTLR 工具版本 4.5.3 与当前运行时版本 4.7.1 不匹配 [英] ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1

查看:44
本文介绍了用于代码生成的 ANTLR 工具版本 4.5.3 与当前运行时版本 4.7.1 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 DataBindingMapperImpl.java 中收到一个特定数据绑定的错误,导致在构建项目时出现以下错误.

<块引用>

用于代码生成的 ANTLR 工具版本 4.5.3 与当前运行时版本 4.7.1 不匹配.
用于解析器编译的 ANTLR 运行时版本 4.5.3 与当前运行时版本 4.7.1 不匹配

用于代码生成的 ANTLR 工具版本 4.5.3 与当前运行时版本 4.7.1 不匹配
用于解析器编译的 ANTLR 运行时版本 4.5.3 与当前运行时版本 4.7.1 不匹配
/Users/casper/Documents/ARCore/Name/app/build/generated/source/kapt/nameDebug/com/company/name/DataBinderMapperImpl.java:10:错误:找不到符号

import com.company.name.databinding.ActivitySplashScreenBindingImpl;^符号:类 ActivitySplashScreenBindingImpl>任务 :app:kaptNameDebugKotlin 失败>任务 :app:mergeExtDexNameDebug位置:包 com.company.name.databindingFAILURE:构建失败,出现异常.

接着是下面的错误信息...

我关注了类似的帖子 here 导致了这个,这是上面错误消息的结尾.

FAILURE:构建失败,出现异常.* 什么地方出了错:任务 ':app:kaptNameDebugKotlin' 执行失败.>执行 org.jetbrains.kotlin.gradle.internal.KaptExecution 时发生故障>java.lang.reflect.InvocationTargetException(无错误信息)

我也试过

  1. 清理项目,然后重建项目
  2. 文件 ->使缓存无效/重新启动
  3. 开启和关闭 Android Studio

连接到数据绑定的布局文件是这样的

<layout xmlns:tools="http://schemas.android.com/tools"xmlns:android=http://schemas.android.com/apk/res/android"xmlns:app=http://schemas.android.com/apk/res-auto"><数据><变量名称=视图模型"type=com.company.name.ui.splashScreen.viewModel.SplashScreenViewModel"/><变量名称=tryAgainBtnHandler"type=com.company.name.ui.splashScreen.viewModel.interfaces.TryAgainBtnHandler"/></数据><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width=match_parent"android:layout_height=match_parent"工具:上下文=.ui.splashScreen.view.SplashScreenActivity">

解决方案

错误是由错误引起的.我确实通过

设置了可见性

android:visibility="@{viewmodel.errorContainerVisible ?View.VISIBLE : View.GONE}"

忘记导入

<import type="android.view.View"/>

解决方案

免责声明:

<块引用>

以下修复旨在解决某些特定问题依赖项冲突,主要是数据绑定问题会导致此错误,但只是错误的 XML 或代码的结果和在这种情况下,下面的解决方案将不起作用.在尝试以下解决方案之前,请仔细检查您的 XML/代码的正确性.

这是一些数据绑定版本的已知问题(嵌入在 Android Studio 中)和其他依赖项,如 Room 导入不同版本的 org.antlr:antlr4 库.

更新:12/06/2020 (dd/MM/yyyy)

<块引用>

如果您使用 Room,请更新到 Room 2.3.0-alpha01 或更高版本应该会消除错误,因为他们已经在此处解决了问题:https://issuetracker.google.com/issues/150106190


将此配置放入应用程序 build.gradle

//groovy配置.所有{resolutionStrategy.force "org.antlr:antlr4-runtime:4.7.1";resolutionStrategy.force "org.antlr:antlr4-tool:4.7.1";}//kotlin DSL配置.所有{解析策略{force("org.antlr:antlr4-runtime:4.7.1")force("org.antlr:antlr4-tool:4.7.1")}}

<块引用>

如果还有问题,可以尝试使用上面的4.5.3版本而不是 4.7.1 来降级库

参考

I'm getting an error in DataBindingMapperImpl.java for one specific data binding which results in the following error when building the project.

ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1.
ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1

ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1
ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1
/Users/casper/Documents/ARCore/Name/app/build/generated/source/kapt/nameDebug/com/company/name/DataBinderMapperImpl.java:10: error: cannot find symbol

import com.company.name.databinding.ActivitySplashScreenBindingImpl;

                                                ^

symbol:   class ActivitySplashScreenBindingImpl

> Task :app:kaptNameDebugKotlin FAILED
> Task :app:mergeExtDexNameDebug
location: package com.company.name.databinding
FAILURE: Build failed with an exception.

followed by the error message below...

I followed the similar post here which resulted in this, which is the end of the error message above.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptNameDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)

I have also tried

  1. Clean Project and then Rebuild project
  2. File -> Invalidate Caches / Restart
  3. Turn Android Studio on and off

The layout file connected to the data binding looks like this

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
    <variable
        name="viewmodel"
        type="com.company.name.ui.splashScreen.viewModel.SplashScreenViewModel"/>
    <variable
        name="tryAgainBtnHandler"
        type="com.company.name.ui.splashScreen.viewModel.interfaces.TryAgainBtnHandler"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.splashScreen.view.SplashScreenActivity">

Solution

The error was caused by a mistake. I did set visibility by

android:visibility="@{viewmodel.errorContainerVisible ? View.VISIBLE : View.GONE}"

and forgot to import

<data>
    <import type="android.view.View"/>

解决方案

Disclaimer:

The fix below is intended to solve a specific problem with some dependencies conflict, mostly databinding issues can cause this error but are only a consequence of wrong XML or code and the solution below will not work in this case. Double check your XML/code correctness before trying the below solution.

This is a known problem with some databinding versions (which is embedded in Android Studio) and other dependencies like Room which import different versions of org.antlr:antlr4 library.

UPDATE: 12/06/2020 (dd/MM/yyyy)

If you use Room, updating to Room 2.3.0-alpha01 or above should remove the error because they have fixed the problem here: https://issuetracker.google.com/issues/150106190


Put this configuration in the app build.gradle

//groovy
configurations.all {
    resolutionStrategy.force "org.antlr:antlr4-runtime:4.7.1"
    resolutionStrategy.force "org.antlr:antlr4-tool:4.7.1"
}

//kotlin DSL
configurations.all {
    resolutionStrategy {
        force("org.antlr:antlr4-runtime:4.7.1")
        force("org.antlr:antlr4-tool:4.7.1")
    }
}

If you still have problems, you can try using the 4.5.3 version above instead of 4.7.1 to downgrade the library

Reference

这篇关于用于代码生成的 ANTLR 工具版本 4.5.3 与当前运行时版本 4.7.1 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆