为什么 Kotlin 的新 LiveData 构建器可能更新在我的项目中不起作用

X. *_*oid 1 android viewmodel android-lifecycle kotlin android-livedata

在此处输入图片说明

这是我的依赖项:

 //Room and Lifecycle Libraries
    kapt "androidx.room:room-compiler:2.2.0-alpha02"
    kapt 'androidx.room:room-compiler:2.2.0-alpha02'
    kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha03"
    implementation "androidx.room:room-runtime:2.2.0-alpha02"
    implementation 'androidx.room:room-runtime:2.2.0-alpha02'
    implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0-alpha03"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha03"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha03"
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha03"
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
Run Code Online (Sandbox Code Playgroud)

如您所见,我实现了最终版本,但我无法访问 liveData 构建器。我怎样才能解决这个问题?

jsa*_*mol 5

文档

对于liveData,使用androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01或更高。

所以你只是缺少依赖:

implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03"
Run Code Online (Sandbox Code Playgroud)