В основном у меня есть следующий класс:
class SignInRequest: BaseObservable() {
@Bindable
var email: String = ""
set(value) {
field = value
notifyPropertyChanged(BR.email)
}
@Bindable
var password: String = ""
set(value) {
field = value
notifyPropertyChanged(BR.password)
}
}
Когда я фокусируюсь на BR.email
, я получаю Unresolved reference: email
(то же самое для BR.password
). Как ни странно, если я открою автоматически сгенерированный класс BR, эти переменные будут там. Также проект компилируется правильно, и приложение работает как положено. Просто по какой-то причине Android Studio не может получить доступ к этим переменным.
Это мой модуль build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "it.fisbapp"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// DEFAULT
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// FIREBASE
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-auth:19.2.0'
// DAGGER 2
implementation 'com.google.dagger:dagger:2.22.1'
implementation 'com.google.dagger:dagger-android:2.22.1'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
kapt 'com.google.dagger:dagger-android-processor:2.22.1'
kapt 'com.google.dagger:dagger-compiler:2.22.1'
// KOTLIN ARROW
implementation "io.arrow-kt:arrow-core-data:0.9.0"
// ARCHITECTURE COMPONENTS
kapt "com.android.databinding:compiler:3.2.0-alpha10"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-runtime:2.1.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.1.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-alpha04"
}
apply plugin: 'com.google.gms.google-services'
Версия Gradle: 5.4.1
Android Студийная версия (для Linux): 3.5.3
РЕДАКТИРОВАТЬ
Я забыл упомянуть, что я уже пытался очистить и перестроить проект и сделать недействительным кеш и перезапустить.
Макет:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="viewModel" type="it.fisbapp.ui.welcome.viewmodel.SignInViewModel"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.welcome.fragment.SignInFragment">
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="70dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Guideline
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:layout_constraintGuide_begin="24dp"
android:id="@+id/guideline_left"/>
<androidx.constraintlayout.widget.Guideline
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/guideline_right"
app:layout_constraintGuide_end="24dp"/>
<EditText
android:id="@+id/email"
android:inputType="textEmailAddress"
android:hint="@string/sign_in_layout_edit_text_email_hint"
android:text="@={viewModel.signInRequest.email}"
app:error="@{viewModel.signInRequest.emailError}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:hint="@string/sign_in_layout_edit_text_password_hint"
android:text="@={viewModel.signInRequest.password}"
app:error="@{viewModel.signInRequest.passwordError}"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/email"
android:layout_marginTop="100dp"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"/>
<Button
android:id="@+id/signIn"
android:text="@string/sign_in_layout_button_sign_in"
android:onClick="@{() -> viewModel.onSignIn()}"
app:gone="@{safeUnbox(viewModel.isLoading)}"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/password"
android:layout_marginTop="100dp"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"/>
<TextView
android:id="@+id/gotoSignUp"
android:text="@string/sign_in_layout_label_sign_up"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"
app:layout_constraintTop_toBottomOf="@+id/signIn"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onGotoSignUp()}"/>
<TextView
android:id="@+id/gotoForgotPwd"
android:text="@string/sign_in_layout_label_reset_password"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"
app:layout_constraintTop_toBottomOf="@+id/gotoSignUp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.onGotoResetPwd()}"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@+id/guideline_right"
app:layout_constraintStart_toStartOf="@+id/guideline_left"
app:layout_constraintTop_toBottomOf="@+id/gotoForgotPwd"
android:layout_marginTop="20dp"
app:visible="@{safeUnbox(viewModel.isLoading)}"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
ViewModel:
class SignInViewModel(val authRepository: AuthRepository): BaseViewModel() {
val signInRequest = SignInRequest()
val onSignin = MutableLiveData<Boolean>()
val onError = MutableLiveData<String>()
val onGotoSignUp = MutableLiveData<Boolean>()
val onGotoResetPwd = MutableLiveData<Boolean>()
val isLoading = MutableLiveData<Boolean>().apply { postValue(false) }
fun onSignIn() {
isLoading.postValue(true)
viewModelScope.launch {
if(signInRequest.isValid()) {
val email = signInRequest.email
val pwd = signInRequest.password
authRepository
.signIn(email, pwd)
.fold(
ifLeft = { onError.postValue(it.errMsg) },
ifRight = { onSignin.postValue(true) }
)
}
isLoading.postValue(false)
}
}
fun onGotoSignUp() {
onGotoSignUp.postValue(true)
}
fun onGotoResetPwd() {
onGotoResetPwd.postValue(true)
}
}