Reputation: 1051
I'm starting with Databinding, but I can not run the project once I create an onClick
function, this is my layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="userViewModel"
type="com.myproject.example.UserViewModel" />
</data>
....
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@={userViewModel.saveOrUpdateButton}"
android:onClick="@={() -> userViewModel.saveOrUpdate()}"
/>
The issue that it appears only when I run ./gradlew :app:kaptDebugKotlin --stacktrace
it points on the onClick() mehtod
Also this
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
Caused by: org.jetbrains.kotlin.kapt3.base.util.KaptBaseError: Exception while annotation processing
My build.gradle
contains :
apply plugin: 'kotlin-kapt'
dataBinding { enabled = true }
And the dependencies :
dependencies {
def lifecycle_version = "2.2.0"
def room_version = "2.2.3"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
//coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
Is something I'm missing?
Upvotes: 2
Views: 1323
Reputation: 9712
@=
is used for two-way data-binding, for onClick
you should use @
android:onClick="@{() -> userViewModel.saveOrUpdate()}"
https://developer.android.com/topic/libraries/data-binding/expressions#event_handling
Upvotes: 8