ANTLR Tool version 4.5.3 used for code generation

2020-07-02 09:10发布

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

4条回答
放我归山
2楼-- · 2020-07-02 09:41

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 AS) and other dependencies like Room which import different versions of org.antlr:antlr4 library.

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

Starting with Room 2.3.0-alpha01 the error should not appear anymore 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

查看更多
\"骚年 ilove
3楼-- · 2020-07-02 09:44

In my project, this error was caused by an incorrect query in one of my Room DAOs. Fixing the query removed the error.

It's unfortunate the error message doesn't clearly indicate the source of the error.

查看更多
该账号已被封号
4楼-- · 2020-07-02 09:49

I got the same error, in my case it was caused due to wrong imports in xml layout.I refactored and changed my package name but that didn't changed the same inside xml files.It showed me the same error.I went through all the fragments,activities and layouts to check if there was any wrong imports/missing imports.After clearing all the import and variable issues, the build was successful.

<data class="MainActivityBinding">

    <variable
        name="vm"
        type="com.abcd.efg.home.MapViewModel" />
</data>

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/includeAppBar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <FrameLayout
                android:id="@+id/toolbar_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@color/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay"
                    app:title="@string/app_name"
                    app:titleTextColor="@color/white" />
            </FrameLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <fragment
            android:id="@+id/navigation"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/includeAppBar"
            app:navGraph="@navigation/nav_main" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/sideNV"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/drawerBackground"
        android:fitsSystemWindows="true"
        android:shadowColor="@color/white"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

查看更多
We Are One
5楼-- · 2020-07-02 09:53

This was a very frustrating problem for me to solve. As this error was covering up the real problem. And as mentioned by @MatPag above, this indeed is not specific to some problem, it could be anything.

After hours of trying anything that I could find on the web, I had the idea to check the generated files in the Android Project View sidebar, and by chance I noticed some errors in the dataBinding generated files. The way to solve this is to understand those errors and fix them in the XML files. For me it was some conflict in variable names.

查看更多
登录 后发表回答