Question

Fix KaptExecution Error in Android Kotlin: Data Binding and Build Generation

kotlinandroidandroid-studio

Question

I suddenly started getting this Android build error, and I am not sure why. If someone can point out where the actual problem is, that would already be very helpful. I suspect it may be related to a recent Android Studio update.

Here is the error output:

Task :app:kaptDebugKotlin
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
C:\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
location: package com.kotlin_developer.margincalculator.databinding

Task :app:kaptDebugKotlin FAILED

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

I want to understand what this error actually means and where I should look first to fix it.

Short Answer

By the end of this page, you will understand what kaptDebugKotlin errors usually mean in Android projects, how generated code like Data Binding classes can fail, why the cannot find symbol message is often the real clue, and how to debug build failures step by step.

Concept

In Android Kotlin projects, kapt stands for Kotlin Annotation Processing Tool. It is used to generate code during the build process for libraries and Android features such as:

  • Data Binding
  • Room
  • Dagger/Hilt
  • Glide
  • Other annotation-based tools

When kaptDebugKotlin fails, the top-level error often looks vague:

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

That message is usually not the real root cause. It only tells you that code generation failed somewhere during annotation processing.

In the error shown here, the most important line is:

cannot find symbol
import com.kotlin_developer.margincalculator.databinding.FragmentCalculatorScreenBindingImpl;

This means the build expected a generated Data Binding implementation class named FragmentCalculatorScreenBindingImpl, but that file was not created successfully.

That usually points to one of these problems:

  • A Data Binding XML layout has an error
  • The layout file name and expected binding class do not match
  • The layout is missing the correct <layout> root for Data Binding
  • A generated file is stale or corrupted in the build folder
  • Gradle, plugin, or dependency versions are out of sync after an update

The ANTLR warnings in the log may look scary, but in this case they are likely secondary warnings, not the main failure. The best debugging habit is to find the first meaningful compilation error, especially cannot find symbol, unresolved reference, or XML/Data Binding generation errors.

This matters in real programming because Android builds rely heavily on generated sources. If one generated class fails, many unrelated-looking build errors can appear afterward.

Mental Model

Think of the Android build process like a factory assembly line.

  • Your XML layouts, Kotlin files, and annotations are the raw materials.
  • Tools like kapt are machines that create extra parts automatically.
  • Data Binding generates Java/Kotlin classes based on layout files.

If one machine fails to create a part, the next machine says:

"I cannot find the part I expected."

That is exactly what cannot find symbol means here. The system expected FragmentCalculatorScreenBindingImpl, but the class was never produced.

So the real question is usually not:

Why does kapt fail?

It is:

What stopped kapt from generating the class it needed?

Take Quiz

Syntax and Examples

The key skill here is learning how to read Android build errors.

Example of a generated binding class expectation

If you have a layout file like:

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="title"
            type="String" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@{title}" />
    </LinearLayout>
</layout>

saved as:

fragment_calculator_screen.xml

Android Data Binding will generate a binding class based on that file name, such as:

FragmentCalculatorScreenBinding

Internally, Android may also generate implementation classes like:

FragmentCalculatorScreenBindingImpl

If generation fails, code that depends on those files will also fail.

Typical setup in build.gradle

android {
    buildFeatures {
        dataBinding true
    }
}

If Data Binding is not enabled correctly, generated binding classes may not appear.

Example of using a generated binding class

class CalculatorFragment : Fragment() {

    private var _binding: FragmentCalculatorScreenBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentCalculatorScreenBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

If the layout file is broken, misnamed, or not using Data Binding properly, this generated binding class may never be created.

What part of the error matters most

From the log:

cannot find symbol
import com.kotlin_developer.margincalculator.databinding.FragmentCalculatorScreenBindingImpl;

This tells you the build is failing around generated binding code, not necessarily your Kotlin business logic.

Step by Step Execution

Use this small debugging process whenever kapt fails.

Example error

error: cannot find symbol
import com.example.app.databinding.FragmentProfileBindingImpl;

Step-by-step thinking

1. The build starts annotation processing

Gradle runs kaptDebugKotlin.

This stage generates source files for features like Data Binding.

2. Data Binding expects to generate classes from XML

Suppose you have a layout file named:

fragment_profile.xml

Android expects to generate classes related to that layout.

3. Generation silently fails because of a layout issue

For example, imagine the XML contains an invalid binding expression:

android:text="@{user.name"

Notice the missing closing }.

Now the binding class generation may fail.

4. Another generated file tries to reference that missing class

Later in the build, a generated file imports:

import com.example.app.databinding.FragmentProfileBindingImpl;

But that class does not exist.

5. The compiler reports cannot find symbol

This is the visible error, but the true root cause is earlier: the layout or generation step failed.

Practical debugging order

When you see this kind of log:

  1. Look for cannot find symbol
  2. Identify the missing generated class name
  3. Map it back to the layout or annotation source
  4. Check related XML, naming, and build feature configuration
  5. Clean and rebuild after fixing the source issue

Mapping class names to layout files

If the missing class is:

FragmentCalculatorScreenBindingImpl

The related layout is very likely:

fragment_calculator_screen.xml

Real World Use Cases

This concept appears often in real Android projects.

1. Data Binding layouts

A screen layout contains binding expressions such as:

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

If the expression, variable type, or layout wrapper is wrong, generated classes fail.

2. Room database builds

Room generates DAO and database code from annotations. A mistake in an entity or query can surface as a kapt error.

3. Dagger or Hilt dependency injection

Missing modules, wrong annotations, or circular dependencies can fail during annotation processing.

4. Android Studio or Gradle updates

After a toolchain update, cached generated files may become incompatible, causing sudden build failures even if app code did not change.

5. Multi-module Android apps

One module may generate code that another module expects. If generation fails in one place, a different module may show the visible error.

Take Quiz

Real Codebase Usage

In real projects, developers usually debug kapt failures by narrowing the problem to the source of generated code.

Common patterns developers use

Guard clause thinking

Treat the top-level KaptExecution error as a wrapper. Search immediately for:

  • cannot find symbol
  • unresolved reference
  • XML parsing errors
  • Data Binding errors
  • Annotation processor-specific messages

Clean rebuild workflow

A common fix sequence is:

  1. Build > Clean Project
  2. Build > Rebuild Project
  3. Delete .gradle and build folders if needed
  4. Sync Gradle again

This is especially useful after dependency or Android Studio updates.

Validation of generated-source inputs

Developers verify the source files that produce generated code:

  • XML layout names
  • <layout> root usage
  • dataBinding enabled in Gradle
  • Valid binding expressions
  • Matching package names

Version consistency

When builds start failing after updates, developers compare:

  • Kotlin plugin version
  • Android Gradle Plugin version
  • Gradle wrapper version
  • Annotation processor library versions

Error isolation

A useful habit is to temporarily simplify the suspect layout or annotation source. For example:

  • Remove complex binding expressions
  • Replace expressions with static text
  • Comment out recent changes
  • Rebuild and reintroduce pieces one by one

This helps identify the exact source that blocks generation.

Common Mistakes

1. Focusing only on the top-level KaptExecution message

Beginners often stop here:

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

But this is usually only a wrapper error.

Better approach

Scroll further up or down and find the first specific compile error.


2. Ignoring the missing generated class name

If the error mentions:

FragmentCalculatorScreenBindingImpl

that strongly suggests the related layout file is:

fragment_calculator_screen.xml

Check that file first.


3. Using Data Binding without the correct XML structure

Broken example

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello" />
</LinearLayout>

If you expect a binding class, this may be wrong because Data Binding usually requires a <layout> root.

Correct example

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello" />
    </LinearLayout>
</layout>

4. Invalid binding expressions in XML

Broken example

android:text="@{viewModel.total"

Fix

Make sure binding expressions are syntactically correct:

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

5. Forgetting to enable Data Binding

Check Gradle config

android {
    buildFeatures {
        dataBinding true
    }
}

Without this, expected binding classes may not be generated.


6. Trusting stale build output

Sometimes the source is already fixed, but stale generated files remain.

Fix

  • Clean project
  • Rebuild project
  • In stubborn cases, delete build directories manually

7. Assuming every warning is the root cause

The ANTLR version mismatch warnings may need attention, but the most actionable error in this case is still the missing generated binding class.

Start with the direct compile failure first.

Comparisons

Wrapper error vs real error

Error typeExampleWhat it meansWhat to do
Wrapper errorA failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecutionAnnotation processing failed somewhereKeep searching for the detailed cause
Real compile errorcannot find symbol FragmentCalculatorScreenBindingImplA required generated class is missingCheck the related layout or generated source input

Data Binding issue vs dependency version issue

Problem typeTypical signsFirst place to check
Data Binding generation failureMissing ...Binding or ...BindingImpl classRelated XML layout file
Dependency/plugin mismatchMany unrelated build failures after updateGradle, Kotlin, AGP versions
Cache/generated file corruptionSuddenly fails without code changeClean/rebuild, delete build caches

View Binding vs Data Binding

FeatureView BindingData Binding
Generates binding class from layoutYesYes
Supports @{} expressions in XMLNoYes
Requires <layout> root for expressionsNoYes
More likely to involve annotation processing complexityLessMore

If your project uses XML expressions and generated implementation classes, you are likely dealing with Data Binding, not just View Binding.

Take Quiz

Cheat Sheet

Quick debugging checklist for kaptDebugKotlin

  • Do not stop at KaptExecution
  • Find the first real error like:
    • cannot find symbol
    • unresolved reference
    • XML parse error
  • If missing class contains Binding or BindingImpl, inspect the related layout XML
  • Map class name to layout name:
    • FragmentCalculatorScreenBinding -> fragment_calculator_screen.xml
  • Check Data Binding setup:
android {
    buildFeatures {
        dataBinding true
    }
}
  • Verify layout uses correct structure if Data Binding is intended:
<layout>
    ...
</layout>
  • Check for:
    • invalid XML
    • invalid @{} expressions
    • wrong variable types
    • renamed layout files
    • package mismatches
  • After fixing source issues:
    • Clean project
    • Rebuild project
    • Sync Gradle
  • If problem started after update:
    • verify Kotlin/Gradle/AGP compatibility
    • clear stale build output

Important interpretation rule

cannot find symbol ...BindingImpl

Usually means:

A generated Data Binding class was expected but was not created.

FAQ

What does A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution mean?

It means annotation processing failed during the build. The message itself is generic, so you need to inspect the more specific errors around it.

What is the real error in this build log?

The most useful error is cannot find symbol for FragmentCalculatorScreenBindingImpl. That suggests a Data Binding generated class is missing.

Why would a binding class suddenly stop generating?

Common reasons include a broken XML layout, an invalid binding expression, a renamed file, stale build output, or version mismatches after an update.

How do I know which layout file to inspect?

Convert the binding class name to snake_case. For example, FragmentCalculatorScreenBinding usually maps to fragment_calculator_screen.xml.

Are the ANTLR warnings the main problem?

Not necessarily. They may indicate a version mismatch, but the direct compile failure here is the missing binding implementation class.

Should I clean and rebuild the project?

Yes. After checking the related layout and configuration, cleaning and rebuilding is one of the first practical fixes.

Does Data Binding require special Gradle configuration?

Yes. You typically need to enable it in the Android module using buildFeatures { dataBinding true }.

Can Android Studio updates trigger this kind of issue?

Yes. Updates can expose dependency mismatches or invalidate cached/generated files, especially in projects using annotation processors.

Take Quiz

Mini Project

Description

Build a small Android screen that uses Data Binding correctly, then practice debugging by understanding how the generated binding class depends on the XML layout. This project demonstrates how layout structure and Gradle configuration affect code generation.

Goal

Create a working fragment layout with Data Binding enabled and access the generated binding class from Kotlin without build errors.

Requirements

  • Enable Data Binding in the app module Gradle configuration.
  • Create a layout file named fragment_calculator_screen.xml using a valid <layout> root.
  • Add one variable and bind it to a TextView.
  • Inflate the generated binding class from a Fragment.
  • Verify the project builds successfully after a clean rebuild.
Take Quiz

Keep learning

Related questions

View more