InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.08k stars 719 forks source link

activityViewModel cannot be created version core 3.5.3, android 3.4.0 . #1764

Closed hoangchungk53qx1 closed 7 months ago

hoangchungk53qx1 commented 10 months ago

Describe the bug activityViewModel cannot be created version core 3.5.3, android 3.4.0 . It works well with android version 3.3.3

at org.koin.androidx.viewmodel.parameter.AndroidParametersHolder.<init>(AndroidParametersHolder.kt:13)
                                                                                                        at org.koin.androidx.viewmodel.factory.KoinViewModelFactory.create(KoinViewModelFactory.kt:24)
                                                                                                        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:184)
                                                                                                        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.kt:150)
                                                                                                        at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel(GetViewModel.kt:44)
                                                                                                        at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel$default(GetViewModel.kt:29)
                                                                                                        at com.rxmobileteam.android004.demo_app_lec9.features.search.SearchFragment$special$$inlined$activityViewModel$default$2.invoke(FragmentActivityVM.kt:83)
                                                                                                        at com.rxmobileteam.android004.demo_app_lec9.features.search.SearchFragment$special$$inlined$activityViewModel$default$2.invoke(FragmentActivityVM.kt:49)
                                                                                                        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)

Koin module and version: implementation("io.insert-koin:koin-core:3.5.3") implementation("io.insert-koin:koin-android:3.4.0")

Snippet or Sample project to help reproduce

  private val demoViewModel: DemoViewModel by activityViewModel<DemoViewModel>()
  class DemoViewModel : ViewModel() {
    fun call() {
       Log.d("DemoViewModel", "call")
    }
}
val viewModelModule = module {
  viewModel {
    DemoViewModel()
  }
}
//   androidContext cannot be created, i have to use this solution
class XXXApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    startKoin {
      androidLogger()
      modules(
        viewModelModule,
        module {
          single { this@XXXApplication } binds arrayOf(Context::class,Application::class)
        }
      )
    }
  }
}
hoangchungk53qx1 commented 10 months ago

https://github.com/InsertKoinIO/koin/issues/1735 androidContext Seems like

arnaudgiuliani commented 8 months ago

Why do you use koin-android and koin-core in different versions?

hoangchungk53qx1 commented 8 months ago

Why do you use koin-android and koin-core in different versions?

Same error on latest version It work on version 3.3.3

arnaudgiuliani commented 7 months ago

let's follow on https://github.com/InsertKoinIO/koin/issues/1735