3

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.

Laura
  • 2,653
  • 7
  • 37
  • 59
  • Why 0.9.3 instead of 2.0.1? – EpicPandaForce Dec 14 '19 at 12:30
  • For koin-android-architecture lib that's the latest stable version. I tried with 2.0.1 but it didn't work so I searched what's the latest version on maven and I found this https://mvnrepository.com/artifact/org.koin/koin-android-architecture?repo=jcenter – Laura Dec 14 '19 at 15:31
  • Interesting, that probably means you can remove it from your project as it is discontinued artifact – EpicPandaForce Dec 14 '19 at 16:35

1 Answers1

11

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 :)

Laura
  • 2,653
  • 7
  • 37
  • 59