koin icon indicating copy to clipboard operation
koin copied to clipboard

NoSuchMethodError - koinIject crash on KMP

Open bpappin opened this issue 8 months ago • 3 comments

Describe the bug Internal exception calling koinInject. Causes a crash immediately when called.

java.lang.NoSuchMethodError: No static method access$koinInject$lambda-0(Landroidx/compose/runtime/State;)Lkotlin/jvm/functions/Function0; in class Lorg/koin/compose/InjectKt; or its super classes (declaration of 'org.koin.compose.InjectKt' appears in /data/app/~~8NvvHAO4vHT_p1JK5g62Zg==/app.occurrence-V_d_XL9ShRbv73nslq-Wew==/base.apk!classes26.dex)
                                         	at io.github.aughtone.framework.navigation.NavControllerProviderKt$rememberNavRouter$$inlined$koinInject$1.invoke(Inject.kt:47)

To Reproduce Steps to reproduce the behavior:

The local class that is calling the function that triggers the crash is:

@Composable
fun rememberNavRouter(
    navController: NavHostController,
): NavRouter {
    koinInject<NavControllerProvider>().apply {
        reset(navController)
    }
    val navRouter = koinInject<NavRouter>()
    return remember { navRouter }
}

class NavControllerProvider {
    private lateinit var navController: NavHostController

    fun get() = navController

    fun reset(navController: NavHostController) {
        this.navController = navController
    }
}

(The purpose of thiseclass is to ensure the NavController survives activity reload during an event like a rotation)

This class is called from a top level composable with:

val navController: NavHostController = rememberNavController()
val router: NavRouter = rememberNavRouter(navController)

The NavRouter is simply a common wrapper around the NavController.

Expected behavior I expect it not to crash :)

Koin module and version: KMP project targetSdk = "35" minSdk="26" kotlin = "2.1.10" compose-multiplatform = "1.7.3" koin = "4.0.0"

bpappin avatar Apr 19 '25 15:04 bpappin

I just updated to Koin 4.0.4 and the problem is still present.

bpappin avatar Apr 19 '25 15:04 bpappin

Getting a similar crash in my KMP project.

Fatal Exception: java.lang.NoSuchMethodError: No static method createScope$default(Lorg/koin/core/Koin;Ljava/lang/String;Lorg/koin/core/qualifier/Qualifier;Ljava/lang/Object;ILjava/lang/Object;)Lorg/koin/core/scope/Scope; in class Lorg/koin/core/Koin; or its super classes

skymansandy avatar Jun 13 '25 05:06 skymansandy

Could it be due to koin version mismatch error?

skymansandy avatar Jun 13 '25 06:06 skymansandy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 11 '25 03:11 stale[bot]