This appears to be related to a bug already reported against androidx.lifecycle
pre-release of 2.3.0 https://issuetracker.google.com/issues/169249668.
Workarounds I have found:
- turn off or reduce severity of
NullSafeMutableLiveData
in
build.gradle
android {
...
lintOptions {
disable 'NullSafeMutableLiveData'
}
}
or lint.xml
in root dir
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="NullSafeMutableLiveData" severity="warning" />
</lint>
- Do the work for
MutableLiveData
encapsulation via backing properties dance (which really hurts my eyes).
class ExampleViewModel : ViewModel() {
private val _data1 = MutableLiveData<Int>()
val data1: LiveData<Int> = _data1
private val _data2 = MutableLiveData<Int?>()
val data2: LiveData<Int?> = _data2
fun funct() {
_data1.value = 1
_data2.value = null
}
}