architecture-samples icon indicating copy to clipboard operation
architecture-samples copied to clipboard

[todo-mvp-databinding] DataBinding class does not generated automatically

Open tennkou opened this issue 6 years ago • 1 comments

Android Studio and Gradle Version:3.4.1 Gradle Plugin Version:5.1.1 kotlin support

code: dataBinding { enabled = true } annotationProcessor "com.android.databinding:compiler:3.1.4"

Earlier, I use version 3.0.1 and 4.1. It worked well, DataBinding class can be generated automaticlly. When i upgrade to 3.4.1 and 5.1.1. The databinding class does not generated automatically, it can be generated after rebuild (or "make project", or keymap command + F9).

when i use kapt "com.android.databinding:compiler:3.1.4", it also not work.

What should i do to make databinding class be generated automatically

tennkou avatar Jun 10 '19 11:06 tennkou

You're encountering an issue where DataBinding classes are not generated automatically after upgrading to:

Android Studio 3.4.1

Gradle 5.1.1

Android Gradle Plugin (AGP) and possibly Kotlin support

This is a known issue that has affected some setups around those versions. Here's a short summary of what's going wrong and how to fix it:

Issue With AGP 3.4.1 and Gradle 5.1.1, the DataBinding compiler doesn’t trigger automatically on code changes. It only works after a manual build, such as:

Build > Rebuild Project

Pressing Cmd+F9 / Ctrl+F9

Make Project

Fixes / Workarounds

  1. Use the correct compiler for Kotlin If you're using Kotlin, you should not use annotationProcessor — instead, use kapt and apply the kapt plugin:

// In build.gradle (app) apply plugin: 'kotlin-kapt'

android { ... dataBinding { enabled = true } }

dependencies { kapt "com.android.databinding:compiler:3.1.4" } com.android.databinding:compiler is deprecated in later AGP versions. You don't need it in AGP >=3.5.0, as DataBinding is bundled in.

  1. Upgrade to a newer Android Gradle Plugin version If possible, update to a newer AGP version (e.g. 3.5 or higher):

classpath "com.android.tools.build:gradle:3.5.4" This fixes many issues with incremental annotation processing and Kotlin compatibility.

  1. Trigger generation manually as a workaround Until you upgrade:

Use Build > Rebuild Project

Or Cmd/Ctrl + F9 (Make Project)

Or run:

./gradlew assembleDebug This will force the DataBinding class to be generated.

VaradGupta23 avatar Jul 21 '25 09:07 VaradGupta23