Update: FIXED :wave: Has anyone run into a Jetpac...
# compose
a
Update: FIXED 👋 Has anyone run into a Jetpack-Compose
beta01
compiler error when using the latest Koin
3.0.1-alpha-6
, and injecting a viewmodel instance via
getViewModel()
in your @Composable function?
Internal error: Couldn't inline method call 'getViewModel'
(further stacktrace in thread)
Copy code
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'getViewModel' into
@androidx.compose.material.ExperimentalMaterialApi @android.annotation.SuppressLint @androidx.compose.runtime.Composable public fun StationDetailScreen(stationName: kotlin.String?, stationId: kotlin.Long?, latitude: kotlin.String?, longitude: kotlin.String?, distanceTo: kotlin.Float?, navHostController: androidx.navigation.NavHostController, `$composer`: androidx.compose.runtime.Composer?, `$changed`: <http://kotlin.Int|kotlin.Int>): kotlin.Unit defined in com.Autolean.puregas.ui.stationDetail
<no source>
Cause: getViewModel (Lorg/koin/core/qualifier/Qualifier;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)Landroidx/lifecycle/ViewModel;:
  @Landroidx/compose/runtime/Composable;() // invisible
e
Hello! This is a known issue. https://github.com/InsertKoinIO/koin/issues/1006 The workaround is in the comments. 😊
👍 1
a
❤️ my hero
❤️ 1
thank you i added this method to my project:
Copy code
/**
 * Resolve ViewModel instance
 *
 * @param qualifier
 * @param parameters
 *
 * @author Arnaud Giuliani
 */
@Composable
inline fun <reified T : ViewModel> getViewModel(
        qualifier: Qualifier? = null,
        noinline parameters: ParametersDefinition? = null,
): T {
    val owner = AmbientViewModelStoreOwner.current
    return remember {
        owner.getViewModel(qualifier, parameters = parameters)
    }
}
and added the needed compiler flag:
Copy code
"-Xallow-unstable-dependencies"
and im g2g
a
Fixed in Koin 3.0.1-beta-1