I have a simple Android project with MVVM and I am using Koin. These are the versions and dependencies that I have in gradle:
build.gradle
// Koin
implementation "org.koin:koin-core:2.0.1"
implementation "org.koin:koin-android:2.0.1"
implementation "org.koin:koin-androidx-viewmodel:2.0.1"
implementation 'org.koin:koin-androidx-scope:2.0.1'
implementation "org.koin:koin-android-architecture:0.9.3"
And my module is this:
moviesModule
val moviesModule = module {
viewModel { MoviesListViewModel(get()) }
single { createMoviesRepository(get()) }
single { createMoviesInteractor(get(), get()) }
}
And inside the fragment I instantiate my viewModel like this:
private val viewModel by viewModel<MoviesListViewModel>()
But for some reason when I run the app the app crashes with the following
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/dsl/context/ParameterHolderKt;
I don't know what could be wrong.
After some research I figured it out. It seems the problem is the import of the viewModel. I was using:
import org.koin.android.architecture.ext.viewModel
and it should be:
import org.koin.androidx.viewmodel.ext.android.viewModel
Now the project is working :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.