41

This morning I made an update to android studio from 3.0.1 to 3.1.0. After updating the gradle to latest version I still get build error regarding data binding.

My gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

All my errors are like the one below:

/Users/mp/Documents/GitHub/projectx/app/build/generated/source/dataBinding/baseClasses/Staging/debug/me/projectx/asdasd/databinding/GridItemActivityTypeBinding.java:57: error: cannot find symbol
      @Nullable DataBindingComponent component) {
                ^
  symbol:   class DataBindingComponent
  location: class GridItemActivityTypeBinding

Does anyone have any idea why would my data binding not generate after the android studio 3.1 update? Thanks in advance

Edit 1: Forgot to say, I tried clean/rebuild/invalidate cache & restart/deleted build folder.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Marian Pavel
  • 2,726
  • 8
  • 29
  • 65

20 Answers20

21

Following the update to Android Studio 3.2, this line works for me. I have both Java and Kotlin code (compiler) running in my project.

Add the following to your gradle.properties: android.databinding.enableV2=false

Reason:

Data Binding V2

Data Binding V2 is now enabled by default and is compatible with V1. This means that, if you have library dependencies that you compiled with V1, you can use them with projects using Data Binding V2. However, note that projects using V1 cannot consume dependencies that were compiled with V2.

source (Release Note): https://developer.android.com/studio/releases/

Community
  • 1
  • 1
Xavier
  • 341
  • 3
  • 7
  • This helped me. Probably I started my project with databinding and later on added Room database. But since dependencies were compiled with V1 - is there a way to recompile them? – Олександр Бабіч Oct 28 '18 at 12:23
  • I got this error when i removed androidExtensions { experimental = true } – iamsujan Jan 20 '19 at 20:08
  • 1
    This worked for me in the following situation: I am working on an AAR that depends on an AAR from another group, and for which I have no say or influence. My AAR was using V2 and theirs uses V1. I didn't realize this until I saw your answer. It worked using that switch. – David S Alderson Mar 22 '19 at 16:31
  • 1
    `android.databinding.enableV2=false` is depreciated and should no longer be required. – Bink Feb 17 '20 at 19:12
5

Just Commenting these lines out in graddle-wrapper.properties file helped me solve my problem

#android.enableExperimentalFeatureDatabinding = true
#android.databinding.enableV2=true
Barungi Stephen
  • 759
  • 8
  • 13
4

if you're using kotlin on android studio 3.2 , replace the distributionurl with this line

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

and you'll be asked to change the build tools version to the apprpriate version. once you've done that , remove this line from the app level build.gradle file

kapt 'com.android.databinding:compiler:3.0.1

and build the project. it worked for me.

slenderm4n
  • 292
  • 7
  • 15
4

This might not be the most helpful answer, but in my case this was caused by a completely unrelated issue in my code.

I was receiving 51 error: cannot find symbol: DataBindingComponent errors (in every single Data Binding generated class), and I spent ages removing changes to my XML and ViewModel code trying to find what was causing it.

The problem actually lay in an invalid change I made a Room model. I guess that a Room error might have been obfuscated by all the databinding errors, but the Debug/Scan logs in the terminal didn't point to it.

So review all recent code, even seemingly unrelated changes if you encounter this problem.

Edit: See this SO post about these databinding errors obfuscating other kapt issues (like Room / Dagger)

Squimon
  • 581
  • 5
  • 7
  • I'm facing the same issue, wherever I make invalid changes to room related components it gives me data binding error, so I was thinking to report it, Have you already reported this issue to https://issuetracker.google.com/issues ? – Parag Pawar Dec 26 '18 at 05:30
  • it's my worst experience with Room I wasted 2 days just for Identifying why showing so many binding errors. bad luck – Ajit Kumar Dubey Apr 01 '19 at 10:49
2

You need to change three things when you update from Android Studio 3.0.1 to 3.1.0. This is as listed below

1) You need to change in gradle.wrapper-properties in distributionUrl. Your URL must be distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

enter image description here To enter image description here

2) Need to update data binding dependancy in app level gradle file from kapt 'com.android.databinding:compiler:3.0.1' to kapt 'com.android.databinding:compiler:3.1.0'

enter image description here

And if you are develop using kotlin then,

3) Third and last thing is need to update kotlin gradle plug in classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.30" to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.31" in project level gradle dependancy. Also you can update build gradle version as seen in below image.

enter image description here

after all above step just clean build and rebuild project. Hope it will work to solve your problem.

Thanks!! Happy coding!!

Sagar Kacha
  • 8,338
  • 4
  • 18
  • 27
  • Did you find a solution? Also tried this approach and did not work The error in my case is cannot find symbol: DataBinderMapper – mitsest Mar 28 '18 at 10:07
  • Still searching for a solution, sorry. If I get something I'll post the answer here – Marian Pavel Mar 29 '18 at 10:16
  • Yes, I have this solution and this work for me. I am also searching other solutions for you if i will get then share will share with you. – Sagar Kacha Mar 29 '18 at 10:25
  • You mean now it's working fine with kotlin right?? Congrats. Happy coding with kotlin. – Sagar Kacha Mar 29 '18 at 14:11
  • I have the exact same configuration but it still doesn't work. Did anyone figure out what is causing this issue? – Anvesh Arrabochu Apr 03 '18 at 03:53
  • @ianveshi Can you please share which issue(error) you are facing on? – Sagar Kacha Apr 03 '18 at 05:19
  • @SaguKacha I was using realm database and had some errors in my model configuration. But I don't know why it caused that issue. Note: Almost all of my fragments/activities are in java and some classes in kotlin. If there's any error anywhere it was using kotlin compiler to compile databinding classes in java. Not sure why its happening though. – Anvesh Arrabochu Apr 04 '18 at 12:45
  • 1
    Definitely helped fix data binding issues for me switching a java/kotlin project to gradle 3.1.0. Thanks! – Paul Ruiz Apr 20 '18 at 17:04
2

Ok, so those who are wondering how I fixed this. The solution is quite simple but probably you won't like it.

I had to move all my classes that were used in data binding in the project root package and after it started to work again.

Marian Pavel
  • 2,726
  • 8
  • 29
  • 65
2

Non of these solutions worked for me so i found out its bug in 3.2 beta 4 version of android studio:

buildscript {

repositories {
...
}
dependencies {
    //classpath "com.android.tools.build:gradle:3.2.0-beta04"  // buggy databinding
    classpath "com.android.tools.build:gradle:3.1.3" // working
}}

after this i sync, rebuild and run everyting correctly

Sagar Zala
  • 4,854
  • 9
  • 34
  • 62
Kebab Krabby
  • 1,574
  • 13
  • 21
  • What is your android studio version and gradle version ? – Kebab Krabby Sep 26 '18 at 11:13
  • I am using Android studio 3.3 Canary 11 with gradle version 4.10, but I figured out the problem it was due to wrong package name in AndroidManifest due to which binding classes were generated in the wrong place and couldn't be referenced where I wanted it to be – Sanjeev Sep 27 '18 at 03:06
  • Not exact the same case, but this solution help me to direct my thought process towards right solution. After updating the gradle plugin to 3.6.1 from 3.2.0. And also updated and corresponding distributionUrl. It hepls me to get rid of the "DataBindingComponent not found error". And the actual error was revealed. – Dhaval Shah Dec 15 '20 at 13:59
2

I had the same issue as @Marian Pavel where my project couldn't compile the databinding components unless I had the class thats used in databinding in the root folder.

I fixed the issue by doing this:

Android Studio: 3.2.1 stable

**project build.gradle**
classpath 'com.android.tools.build:gradle:3.2.1'

**module build.gradle**
apply plugin: 'kotlin-kapt'
kapt "androidx.databinding:databinding-compiler:3.2.1"

**gradle.properties**
android.databinding.enableV2=false
Ali
  • 2,702
  • 3
  • 32
  • 54
ddy214
  • 21
  • 1
  • I had wrong field in my room db class. Which causing compile time Databinding errors. After I added ` android.databinding.enableV2=false ` line to `gradle.properties` and then able to Find out the room Model class error. I have removed this line after rectifying problem. I am using the Android Studio version as mentioned in above answer. – Pradip Tilala Aug 11 '19 at 10:27
  • What is the purpose of **androidx.databinding:databinding-compiler**? – IgorGanapolsky Dec 17 '19 at 17:56
1

To fix this error in Java project you shouild rollback to supportLibraryVersion - 27.0.2 from 27.1.0 Works fine with AndroidStudio 3.1 and com.android.tools.build:gradle:3.1.0

Waiting for a fix from the Google

Alex_297
  • 249
  • 1
  • 8
0

Adding these lines in grade.properties helped me save the issue

android.enableExperimentalFeatureDatabinding = true
android.databinding.enableV2=true
Moses Gitau
  • 947
  • 8
  • 7
0

I was having the same issue. Fixed it by adding google() to Project build.gradle

allprojects {
    repositories {
        jcenter()
        **google()**
    }
}

make sure you add in allProjects

sami qaiser
  • 1
  • 1
  • 4
0

This one is a very tricky bug with android studio and databinding! I had to test all this proposed solutions and some more for an entire day to finally make the databinding compile at least.

So I had to disable all databindind settings in gradle.properties file, just comment these lines or delete them:

android.databinding.enableV2 = true
android.enableExperimentalFeatureDatabinding = true

remove buildToolsVersion from build.gradle and have the following sdk versions:

compileSdkVersion 27
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Plus a couple more clean/rebuild invalidate caches and restart, and it FINALLY compiled. AS engineers are great at creating bugs!

Sergio
  • 2,346
  • 2
  • 24
  • 28
0

Check your xml files if you are using databinding. I wasted one hour today because I renamed one class and Android Studio decided to make changes in my xml files. For example, I had a class named LiveGameModel and I renamed to LiveGameView and AS decided to make changes in xml files which are not related to this view. I know, this bug doesn't make sense.

Nestor Lara
  • 53
  • 1
  • 1
  • 4
0

This may seems strange but I wasted a few hours facing the error and after a inspection in my latest changes I found that it was related to an error in Room database.

I declared one of the Dao interface but forgot to anotate it with @Dao.

After fixing that the data binding error was fixed.

I guess this is a bug of android studio.

Ifta
  • 1,536
  • 18
  • 25
0

I got this error after making some modifications in Room Entity classes. So I feel that This error is somehow related to Room library. Try to revert changes in Room classes and entities or comment them to see if error is fixed.

In my case the error appeared because I was returning int from insert and update methods. These methods should not return anything. So removing return fixed the error.

@Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(student: Student):Int

to

@Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(student: Student)
Thales Minussi
  • 6,965
  • 1
  • 30
  • 48
0

FIRST OF ALL
1. add "layout" to your root layout

  1. Build -> Make Project (for create generate class after add "layout")
  2. //binding private lateinit var binding:ActivityLoginBinding
  3. in oncreate view //setContentView(R.layout.activity_login) binding = DataBindingUtil.setContentView(this@LoginActivity,R.layout.activity_login)
Yudi karma
  • 324
  • 3
  • 15
0
  • In the gradle.properties add:
    android.databinding.enableV2=true

  • In build.gradle(module:app) file add:
    dataBinding {enabled = true}

  • Clean project and rebuid it.

It will start working...

Elletlar
  • 3,136
  • 7
  • 32
  • 38
0

I got this while updating gradle to 3.4.2. All you need to do is remove the import statement of java.lang.

Caution: Android Studio doesn't yet handle imports so the autocomplete for imported variables may not work in your IDE. Your app still compiles and you can work around the IDE issue by using fully qualified names in your variable definitions.

Source: https://developer.android.com/topic/libraries/data-binding/expressions#import-classes

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
0

Just connect to internet and sync project with gradle files. It'll do.

-10

I was having the same issue. I disabled databinding in gradle properties and it worked. dataBinding.enabled = false