Solution 1 :
You will get ‘Unresolved reference…” error when you don’t call invalidateAll method on a binding object.
Make sure you use it like this:
Create a binding field:
private lateinit var binding: ActivityMainBinding
Assign binding object in onCreate:
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
Call invalidateAll() on a binding object:
binding.invalidateAll()
Problem :
I am learning to use data binding in Android Kotlin development and I have linked my data class with my binding object with no compilation errors. However, in order to refresh my binding object to reflect changes to the data object I need to call invalidateAll()
. I am getting ‘Unresolved reference: invalidateAll’ and I can’t figure out why.
Here is my build.gradle(:app):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.aboutme"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
kapt "com.android.databinding:compiler:3.0.0-beta1"
}
I have also imported DataBindingUtil and ViewDataBinding (which registers as unused even though invalidateAll should be a method of ViewDataBinding?)
import androidx.databinding.ViewDataBinding