koin: Crash caused by not founded definitions after migrating to 2.2.2 from 2.0.1

Describe the bug Crashes occurred after upgrading from 2.0.1 to 2.2.2.

In my project I have:

BaseFragment

open class BaseFragment(
    val qualifier: String
) : Fragment() {
    protected val router: AppRouter by inject(named("${qualifier}_ROUTER"))
}

const val SCREEN_A_QUALIFIER = "SCREEN_A"

class ScreenAFragment : BaseFragment(qualifier = SCREEN_A_QUALIFIER)

AppRouter for navigation open class AppRouter

ScreenARouter is a router for ScreenA class ScreenARouter : AppRouter

val screenAModule = module {
    val routerQualifier = named("${SCREEN_A_QUALIFIER}_ROUTER")
    single(routerQualifier) {
        ScreenARouter()
    }
}

screenAModule is loaded at app startup in Application class.

Expected behavior On version 2.0.1 I had no crashes and dependencies resolved correctly. But after updating on 2.2.2 I get a crash that definitions not founded:

 Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'ru.my.project.base.AppRouter' & qualifier:'SCREEN_A_ROUTER'. Check your definitions!
        at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:282)
        at org.koin.core.scope.Scope.resolveInstance(Scope.kt:251)
        at org.koin.core.scope.Scope.get(Scope.kt:204)
        at ru.my.project.base.BaseFragment$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:69)

Koin project used and used version (please complete the following information):

def koin_version = "2.2.2"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"

It seems to me that my problem is caused by that changes - https://github.com/InsertKoinIO/koin/commit/0a71742243c1fee49a64fa2e05f3035b9ec17ab3, where KClass<*> was replaced by KClass<T>. For example:

Was:

fun <T> get(
    clazz: KClass<*>,
    qualifier: Qualifier? = null,
    parameters: ParametersDefinition? = null
): T

Now:

fun <T : Any> get(
    clazz: KClass<T>,
    qualifier: Qualifier? = null,
    parameters: ParametersDefinition? = null
): T

And now I don’t have a clue is it a bug or feature, but now it don’t let to migrate to new version safely.

Thanks in advance for the help.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Similar issue for me: Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'androidx.lifecycle.SavedStateHandle'. Check your definitions!

Looks like it does not create scope properly, however code looks OK.