Question
Fix KaptExecution Error in Android Kotlin: Data Binding and Build Generation
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
buildfolder - 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 , not the main failure. The best debugging habit is to find the first meaningful compilation error, especially , , or XML/Data Binding generation errors.
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
kaptare 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?
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:
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;
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.
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 symbolunresolved reference- XML parsing errors
- Data Binding errors
- Annotation processor-specific messages
Clean rebuild workflow
A common fix sequence is:
Build > Clean ProjectBuild > Rebuild Project- Delete
.gradleandbuildfolders if needed - 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 usagedataBindingenabled in Gradle- Valid binding expressions
- Matching package names
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" />
Comparisons
Wrapper error vs real error
| Error type | Example | What it means | What to do |
|---|---|---|---|
| Wrapper error | A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution | Annotation processing failed somewhere | Keep searching for the detailed cause |
| Real compile error | cannot find symbol FragmentCalculatorScreenBindingImpl | A required generated class is missing | Check the related layout or generated source input |
Data Binding issue vs dependency version issue
| Problem type | Typical signs | First place to check |
|---|---|---|
| Data Binding generation failure | Missing ...Binding or class |
Cheat Sheet
Quick debugging checklist for kaptDebugKotlin
- Do not stop at
KaptExecution - Find the first real error like:
cannot find symbolunresolved reference- XML parse error
- If missing class contains
BindingorBindingImpl, 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
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?
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.xmlusing 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.
Keep learning
Related questions
Android AlarmManager Example: Scheduling Tasks with AlarmManager
Learn how to use Android AlarmManager to schedule tasks, set alarms, and handle broadcasts with a simple beginner example.
Can You Extend a Data Class in Kotlin? Inheritance, Limits, and Better Alternatives
Learn why Kotlin data classes cannot be extended, what causes the component function clash, and which alternatives to use instead.
Difference Between List and Array in Kotlin
Learn the difference between List and Array in Kotlin, including mutability, size, APIs, performance, and when to use each one.