rickclephas / KMP-ObservableViewModel

Library to use AndroidX/Kotlin ViewModels with SwiftUI
MIT License
591 stars 28 forks source link

Unresolved supertypes: androidx.lifecycle.ViewModel #34

Closed MasoudFallahpour closed 1 year ago

MasoudFallahpour commented 1 year ago

I've used the 1.0.0-ALPHA-7 version of the library and followed the README to define a view model in my shared KMM module. When building the project I get the following error: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class com.rickclephas.kmm.viewmodel.KMMViewModel, unresolved supertypes: androidx.lifecycle.ViewModel

I'm not sure why I'm getting this error because as far as I can tell the KMM-ViewModel transitively adds the dependency for the Android ViewModel.

rickclephas commented 1 year ago

Hi sorry about that. There is a small dependency issue in the current version. Could you please add the following dependency to your android module and source set?:

// androidApp/build.gradle.kts
dependencies {
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
}

// shared/build.gradle.kts
val androidMain by getting {
    dependencies {
        implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
    }
}

This will be fixed in the next release 🙂.

MasoudFallahpour commented 1 year ago

Thanks for the quick answer. I think adding just the following dependency would be enough. Isn't it?

// shared/build.gradle.kts
val androidMain by getting {
    dependencies {
        implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
    }
}
rickclephas commented 1 year ago

Yeah that might be sufficient depending on your project 👍🏻