I am using koin v3.2.0 in my jetpack compose application. I am getting weird issue on my viewModelOf
. I imported correctly as well from the sample project.
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.compose.material:material:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha14'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.activity:activity-compose:1.5.0'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.navigation:navigation-compose:$nav_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation 'androidx.work:work-runtime:2.7.1'
implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
implementation "com.airbnb.android:lottie-compose:$lottieVersion"
implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-androidx-compose:$koin_version"
}
AppModule.kt
package com.vivek.sportsresult.di
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module
val appModule = module {
viewModelOf(::MainActivityViewModel)
}
MainActivityViewModel.kt
package com.vivek.sportsresult.viewmodel
import androidx.lifecycle.ViewModel
class MainActivityViewModel : ViewModel() {
}
Image Error
Error is too big I am short description.
one of the following functions can be called with the arguments supplied.
Module.viewModelOf(() → TypeVariable(R)) where R = TypeVariable(R) for inline fun <reified R : ViewModel> Module.viewModelOf(crossinline constructor: () → R): KoinDefinition<R> /* = Pair<Module, InstanceFactory<R>> */ defined in org.koin.androidx.viewmodel.dsl
Can somone guide me please. My Project on Github Thanks
Inside your AppModule.kt import this:
import com.vivek.sportsresult.viewmodel.MainActivityViewModel
Your new AppModule.kt:
package com.vivek.sportsresult.di
import com.vivek.sportsresult.viewmodel.MainActivityViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module
val appModule = module {
viewModelOf(::MainActivityViewModel)
}