I'm newbie with Android databinding library.
I have bunch of warnings such as:
warning: viewModel.someBoolean.getValue() is a boxed field but needs to be un-boxed to execute android:checked. This may cause NPE so Data Binding will safely unbox it. You can change the expression and explicitly wrap viewModel.someBoolean.getValue() with safeUnbox() to prevent the warning
It's defined as follows:
In ViewModel
val someBoolean: MutableLiveData<Boolean> = MutableLiveData()
In Layout
<RadioButton
android:id="@+id/someBooleanRadioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="@={viewModel.someBoolean}"
android:text="@string/boolean_description" />
I tried to fix it by adding safeUnbox() :
<RadioButton
android:id="@+id/someBooleanRadioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="@={safeUnbox(viewModel.someBoolean)}"
android:text="@string/boolean_description" />
But I am geting compilation error:
msg:cannot find method safeUnbox(java.lang.Boolean) in class android.databinding.ViewDataBinding
In gradle already defined
dataBinding {
enabled = true
}
and kapt 'com.android.databinding:compiler:3.1.4'
Any thoughts how to fix it? Android Studio 3.1.4 Gradle 4.4 Kotlin 1.2.61
P.S. just got duplicate on question. All questions is about how to fix warning, but my question is how to fix compilation error when you adding safeUnbox()