我已经实现了互联网上提供的所有依赖,但仍然无法解决这个问题。refered这和这个链接和stackoverflow上的其他链接,但无法解决问题。
我在活动上创建viewModel实例时遇到了问题,在片段中我没有遇到任何挑战。
以下是我的应用程序构建等级:
plugins {
id com.android.application
id org.jetbrains.kotlin.android
id kotlin-android
id kotlin-parcelize
id androidx.navigation.safeargs
id kotlin-kapt
id com.google.dagger.hilt.android
}
dependencies {
implementation androidx.core:core-ktx:1.10.1
implementation androidx.appcompat:appcompat:1.6.1
implementation com.google.android.material:material:1.9.0
implementation androidx.constraintlayout:constraintlayout:2.1.4
implementation androidx.navigation:navigation-fragment-ktx:2.6.0
implementation androidx.navigation:navigation-ui-ktx:2.6.0
implementation androidx.fragment:fragment-ktx:1.6.1
//Retrofit - network calls
implementation com.squareup.retrofit2:retrofit:2.9.0
implementation com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.6
implementation com.squareup.retrofit2:converter-gson:2.9.0
implementation com.google.code.gson:gson:2.9.0
implementation com.google.android.gms:play-services-location:21.0.1
implementation com.google.firebase:firebase-messaging:23.2.0
//Hilt - Dependency Injection
implementation("com.google.dagger:hilt-android:2.44")
kapt("com.google.dagger:hilt-android-compiler:2.44")
//Page lifecycle owners
def lifecycle_version = "2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "android.arch.lifecycle:extensions:1.1.1"
def coroutines_version = "1.6.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
//QR generation library
implementation com.google.zxing:core:3.4.1
testImplementation junit:junit:4.13.2
androidTestImplementation androidx.test.ext:junit:1.1.5
androidTestImplementation androidx.test.espresso:espresso-core:3.5.1
}
Project build gradle :
plugins {
id com.android.application version 7.4.1 apply false
id com.android.library version 7.4.1 apply false
id org.jetbrains.kotlin.android version 1.8.0 apply false
id androidx.navigation.safeargs.kotlin version 2.5.1 apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
}
提前谢谢。