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.
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/
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.
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)
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
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'
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.
after all above step just clean build and rebuild project. Hope it will work to solve your problem.
Thanks!! Happy coding!!
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.
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
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
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
Adding these lines in grade.properties helped me save the issue
android.enableExperimentalFeatureDatabinding = true
android.databinding.enableV2=true
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)
Just Commenting these lines out in graddle-wrapper.properties
file helped me solve my problem
#android.enableExperimentalFeatureDatabinding = true
#android.databinding.enableV2=true
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
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!
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.
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.
FIRST OF ALL
1. add "layout" to your root layout
- Build -> Make Project (for create generate class after add "layout")
- //binding private lateinit var binding:ActivityLoginBinding
- in oncreate view //setContentView(R.layout.activity_login) binding = DataBindingUtil.setContentView(this@LoginActivity,R.layout.activity_login)
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...
I was having the same issue. I disabled databinding in gradle properties and it worked. dataBinding.enabled = false
来源:https://stackoverflow.com/questions/49514488/android-studio-fails-to-generate-databinding-after-3-1-0-update