android – Couldn’t create occasion of ViewModel utilizing Koin

android – Couldn’t create occasion of ViewModel utilizing Koin


I am making an attempt to do a mission in KMP, nevertheless, the app within the Android Model is working like a appeal, however the iOS model crashes immediately.

Right here is the (50% totally) error generated by xcode. I am launching the app from xcode as a result of i’ve some cocoapods dependencies for Maps :

[INFO] [Koin] No Compose Koin context setup, taking default. Use KoinContext(), KoinAndroidContext() or KoinApplication() operate to setup or create Koin context and keep away from such message.
[DEBUG] [Koin] | << parameters
[DEBUG] [Koin] |- 'com.cdm.janaza.MainViewModel' in 5.529 ms
[INFO] [Koin] No Compose Koin context setup, taking default. Use KoinContext(), KoinAndroidContext() or KoinApplication() operate to setup or create Koin context and keep away from such message.
[DEBUG] [Koin] |- 'com.cdm.janaza.core.presentation.navigation.NavigationViewModel'...
[DEBUG] [Koin] | >> parameters DefinitionParameters[]
[DEBUG] [Koin] |- ? t:'com.cdm.janaza.core.presentation.navigation.NavigationViewModel' - q:'null' look in injected parameters
[DEBUG] [Koin] | (+) '[Factory: 'com.cdm.janaza.core.presentation.navigation.NavigationViewModel']'
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomBarService'...
[DEBUG] [Koin] | (+) '[Singleton: 'com.cdm.janaza.core.data.service.BottomBarServiceImpl',binds:com.cdm.janaza.core.domain.service.BottomBarService]'
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomBarService' in 0.017 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.AuthenticationService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.AuthenticationService' in 0.004 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.ToastService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.ToastService' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomSheetService'...
[DEBUG] [Koin] | (+) '[Singleton: 'com.cdm.janaza.core.data.service.BottomSheetServiceImpl',binds:com.cdm.janaza.core.domain.service.BottomSheetService]'
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomSheetService' in 0.013 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.PreferencesDataStoreRepository'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.PreferencesDataStoreRepository' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.PrayerService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.PrayerService' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.UserService'...
[DEBUG] [Koin] | (+) '[Singleton: 'com.cdm.janaza.core.data.service.UserServiceImpl',binds:com.cdm.janaza.core.domain.service.UserService]'
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.FirebaseUserRepository'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.FirebaseUserRepository' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.FirebasePrayerRepository'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.FirebasePrayerRepository' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.UserService' in 0.045 ms
[DEBUG] [Koin] | << parameters
[DEBUG] [Koin] |- 'com.cdm.janaza.core.presentation.navigation.NavigationViewModel' in 0.718 ms
null
WARNING: All log messages earlier than absl::InitializeLog() known as are written to STDERR
I0000 00:00:1737758409.724080 13511090 config.cc:230] gRPC experiments enabled: call_status_override_on_cancellation, http2_stats_fix, monitoring_experiment, pick_first_new, trace_record_callops, work_serializer_clears_time_cache
11.7.0 - [FirebaseFirestore][I-FST000001] AppCheck failed: 'The operation couldn’t be accomplished. The attestation supplier DeviceCheckProvider just isn't supported on present platform and OS model.'
[INFO] [Koin] No Compose Koin context setup, taking default. Use KoinContext(), KoinAndroidContext() or KoinApplication() operate to setup or create Koin context and keep away from such message.
Residence
[INFO] [Koin] No Compose Koin context setup, taking default. Use KoinContext(), KoinAndroidContext() or KoinApplication() operate to setup or create Koin context and keep away from such message.
[DEBUG] [Koin] |- 'com.cdm.janaza.feature_main.presentation.display screen.residence.HomeViewModel'...
[DEBUG] [Koin] | >> parameters DefinitionParameters[]
[DEBUG] [Koin] |- ? t:'com.cdm.janaza.feature_main.presentation.display screen.residence.HomeViewModel' - q:'null' look in injected parameters
[DEBUG] [Koin] | (+) '[Factory: 'com.cdm.janaza.feature_main.presentation.screen.home.HomeViewModel']'
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.AuthenticationService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.AuthenticationService' in 0.003 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.PrayerService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.PrayerService' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.OverlayService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.OverlayService' in 0.002 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.PreferencesDataStoreRepository'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.repository.PreferencesDataStoreRepository' in 0.003 ms
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomSheetService'...
[DEBUG] [Koin] |- 'com.cdm.janaza.core.area.service.BottomSheetService' in 0.003 ms
[ERROR] [Koin] * Occasion creation error : couldn't create occasion for '[Factory: 'com.cdm.janaza.feature_main.presentation.screen.home.HomeViewModel']': kotlin.NullPointerException[kotlin.Exception]
[DEBUG] [Koin] | << parameters
Uncaught Kotlin exception: org.koin.core.error.InstanceCreationException: Couldn't create occasion for '[Factory: 'com.cdm.janaza.feature_main.presentation.screen.home.HomeViewModel']'
nw_endpoint_flow_failed_with_error [C1 2a00:1450:4006:80d::200a.443 failed parent-flow (unsatisfied (No network route))] already failing, returning
nw_connection_get_connected_socket_block_invoke [C1] Shopper known as nw_connection_get_connected_socket on unconnected nw_connection
TCP Conn 0x600003306760 Failed : error 0:50 [50]
I0000 00:00:1737758409.843337 13511151 subchannel.cc:806] subchannel 0x105745b90 {tackle=ipv6:%5B2a00:1450:4006:80d::200apercent5D:443, args={grpc.client_channel_factory=0x60000002f5f0, grpc.default_authority=firestore.googleapis.com, grpc.http2_scheme=https, grpc.inside.channel_credentials=0x600002634cc0, grpc.inside.client_channel_call_destination=0x114efb728, grpc.inside.event_engine=0x60000002fa00, grpc.inside.security_connector=0x600002c3bf00, grpc.inside.subchannel_pool=0x600002928cb0, grpc.keepalive_time_ms=30000, grpc.primary_user_agent=grpc-c++/1.65.1, grpc.resource_quota=0x600000ce6130, grpc.server_uri=dns:///firestore.googleapis.com}}: join failed (UNKNOWN:(area:NSPOSIXErrorDomain, code:50, description:The operation couldn’t be accomplished. Community is down) {grpc_status:2, created_time:"2025-01-24T23:40:09.843187+01:00", file_line:150, file:"/var/folders/hn/5bx1f4_d4ds5vhwhkxc7vdcr0000gn/T/ZipRelease/2024-07-25T04-01-28/project-ios/Pods/gRPC-Core/src/core/lib/transport/error_utils.cc"}), backing off for 989 ms
    at 0   Janaza.debug.dylib                  0x1100e7797        kfun:kotlin.Exception#(kotlin.String?;kotlin.Throwable?){} + 123 
    at 1   Janaza.debug.dylib                  0x111c2ec4b        kfun:org.koin.core.error.InstanceCreationException#(kotlin.String;kotlin.Exception){} + 123 
    at 2   Janaza.debug.dylib                  0x111c30077        kfun:org.koin.core.occasion.InstanceFactory#create(org.koin.core.occasion.ResolutionContext){}1:0 + 1703 
    at 3   Janaza.debug.dylib                  0x111c2f8a7        kfun:org.koin.core.occasion.FactoryInstanceFactory#get(org.koin.core.occasion.ResolutionContext){}1:0 + 103 
    at 4   Janaza.debug.dylib                  0x111c4a467        kfun:org.koin.core.occasion.InstanceFactory#get(org.koin.core.occasion.ResolutionContext){}1:0-trampoline + 67 
    at 5   Janaza.debug.dylib                  0x111c3ac9f        kfun:org.koin.core.registry.InstanceRegistry#resolveInstance(org.koin.core.qualifier.Qualifier?;kotlin.mirror.KClass<*>;org.koin.core.qualifier.Qualifier;org.koin.core.occasion.ResolutionContext){0§}0:0? + 343 
    at 6   Janaza.debug.dylib                  0x111c43757        kfun:org.koin.core.scope.Scope.resolveFromRegistry#inside + 323 
    at 7   Janaza.debug.dylib                  0x111c42bb7        kfun:org.koin.core.scope.Scope.resolveFromContext#inside + 1503 
    at 8   Janaza.debug.dylib                  0x111c41f1f        kfun:org.koin.core.scope.Scope.stackParametersCall#inside + 871 
    at 9   Janaza.debug.dylib                  0x111c41b6f        kfun:org.koin.core.scope.Scope.resolveInstance#inside + 867 
    at 10  Janaza.debug.dylib                  0x111c41547        kfun:org.koin.core.scope.Scope.resolve#inside + 2271 
    at 11  Janaza.debug.dylib                  0x111c40c33        kfun:org.koin.core.scope.Scope#getWithParameters(kotlin.mirror.KClass<*>;org.koin.core.qualifier.Qualifier?;org.koin.core.parameter.ParametersHolder?){0§}0:0 + 159 
    at 12  Janaza.debug.dylib                  0x111c4d203        kfun:org.koin.viewmodel.manufacturing facility.KoinViewModelFactory#create(kotlin.mirror.KClass<0:0>;androidx.lifecycle.viewmodel.CreationExtras){0§}0:0 + 411 
    at 13  Janaza.debug.dylib                  0x110ecfac7        kfun:androidx.lifecycle.ViewModelProvider.Manufacturing facility#create(kotlin.mirror.KClass<0:0>;androidx.lifecycle.viewmodel.CreationExtras){0§}0:0-trampoline + 115 
    at 14  Janaza.debug.dylib                  0x110ecf213        kfun:androidx.lifecycle.viewmodel#createViewModel(androidx.lifecycle.ViewModelProvider.Manufacturing facility;kotlin.mirror.KClass<0:0>;androidx.lifecycle.viewmodel.CreationExtras){0§}0:0 + 131 
    at 15  Janaza.debug.dylib                  0x110ecb387        kfun:androidx.lifecycle.viewmodel.ViewModelProviderImpl#getViewModel(kotlin.mirror.KClass<0:0>;kotlin.String){0§}0:0 + 1163 
    at 16  Janaza.debug.dylib                  0x110ecb5f7        kfun:androidx.lifecycle.viewmodel.ViewModelProviderImpl#getViewModel$default(kotlin.mirror.KClass<0:0>;kotlin.String?;kotlin.Int){0§}0:0 + 311 
    at 17  Janaza.debug.dylib                  0x110ecdfdb        kfun:androidx.lifecycle.ViewModelProvider#get(kotlin.mirror.KClass<0:0>){0§}0:0 + 183 
    at 18  Janaza.debug.dylib                  0x111c4c487        kfun:org.koin.viewmodel#resolveViewModel(kotlin.mirror.KClass<0:0>;androidx.lifecycle.ViewModelStore;kotlin.String?;androidx.lifecycle.viewmodel.CreationExtras;org.koin.core.qualifier.Qualifier?;org.koin.core.scope.Scope;kotlin.Function0?){0§}0:0 + 711 
    at 19  Janaza.debug.dylib                  0x10fd88da7        kfun:com.cdm.janaza.feature_main.presentation.display screen.residence#Residence(androidx.compose.basis.format.PaddingValues;kotlin.Function0;kotlin.Function1;androidx.compose.runtime.Composer?;kotlin.Int){} + 5899 
    at 20  Janaza.debug.dylib                  0x10fc7cc8f        kfun:com.cdm.janaza.core.presentation.navigation.navHost.navGraphBuilder.display screen.residence$lambda$5#inside + 375 
    at 21  Janaza.debug.dylib                  0x10fc7cea7        kfun:com.cdm.janaza.core.presentation.navigation.navHost.navGraphBuilder.display screen.$residence$lambda$5$FUNCTION_REFERENCE$2.invoke#inside + 179 
    at 22  Janaza.debug.dylib                  0x10fc7d06f        kfun:com.cdm.janaza.core.presentation.navigation.navHost.navGraphBuilder.display screen.$residence$lambda$5$FUNCTION_REFERENCE$2.$invoke(androidx.compose.animation.AnimatedContentScope;androidx.navigation.NavBackStackEntry;androidx.compose.runtime.Composer;kotlin.Int){}#inside + 231 
    at 23  Janaza.debug.dylib                  0x110247873        kfun:kotlin.Function4#invoke(1:0;1:1;1:2;1:3){}1:4-trampoline + 131 
    at 24  Janaza.debug.dylib                  0x1105e84b3        kfun:androidx.compose.runtime.inside.ComposableLambdaImpl#invoke(kotlin.Any?;kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 687 
    at 25  Janaza.debug.dylib                  0x1105f605b        kfun:androidx.compose.runtime.inside.ComposableLambdaImpl#$invoke(kotlin.Any?;kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(kotlin.Any?;kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 235 
    at 26  Janaza.debug.dylib                  0x110247873        kfun:kotlin.Function4#invoke(1:0;1:1;1:2;1:3){}1:4-trampoline + 131 
    at 27  Janaza.debug.dylib                  0x111c1e3f7        kfun:androidx.navigation.compose.NavHost$lambda$41$lambda$40#inside + 659 
    at 28  Janaza.debug.dylib                  0x111c22423        kfun:androidx.navigation.compose.$NavHost$lambda$41$lambda$40$FUNCTION_REFERENCE$37.invoke#inside + 119 
    at 29  Janaza.debug.dylib                  0x111c22577        kfun:androidx.navigation.compose.$NavHost$lambda$41$lambda$40$FUNCTION_REFERENCE$37.$invoke(androidx.compose.runtime.Composer;kotlin.Int){}#inside + 159 
    at 30  Janaza.debug.dylib                  0x110239d67        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
    at 31  Janaza.debug.dylib                  0x1105e7d9b        kfun:androidx.compose.runtime.inside.ComposableLambdaImpl#invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 607 
    at 32  Janaza.debug.dylib                  0x1105f5e3f        kfun:androidx.compose.runtime.inside.ComposableLambdaImpl#$invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 163 
    at 33  Janaza.debug.dylib                  0x110239d67        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
    at 34  Janaza.debug.dylib                  0x1104d3097        kfun:androidx.compose.runtime#CompositionLocalProvider(androidx.compose.runtime.ProvidedValue<*>;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){} + 611 
    at 35  Janaza.debug.dylib                  0x110de9abf        kfun:androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider#inside + 2963 
    at 36  Janaza.debug.dylib                  0x110deed37        kfun:androidx.compose.runtime.saveable.SaveableStateHolder#SaveableStateProvider(kotlin.Any;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){}-trampoline + 123 
    at 37  Janaza.debug.dylib                  0x111c25d5b        kfun:androidx.navigation.compose.SaveableStateProvider#inside + 1547 
    at 38  Janaza.debug.dylib                  0x111c26673        kfun:androidx.navigation.compose.LocalOwnersProvider$lambda$0#inside + 475 
    at 39  Janaza.debug.dylib                  0x111c26a3f        kfun:androidx.navigation.compose.$LocalOwnersProvider$lambda$0$FUNCTION_REFERENCE$0.invoke#inside + 119 
    at 40  Janaza.debug.dylib                  0x111c26b93        kfun:androidx.navigation.compose.$LocalOwnersProvider$lambda$0$FUNCTION_REFERENCE$0.$invoke(androidx.compose.runtime.Composer;kotlin.Int){}#inside + 159 
    at 41  Janaza.debug.dylib                  0x110239d67        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
    Suppressed: kotlinx.coroutines.inside.DiagnosticCoroutineContextException: [androidx.compose.runtime.BroadcastFrameClock@da805e8, StandaloneCoroutine{Cancelling}@5daf340, FlushCoroutineDispatcher@db00f28]
        at 0   Janaza.debug.dylib                  0x1100ed6ab        kfun:kotlin.Throwable#(kotlin.String?){} + 99 
        at 1   Janaza.debug.dylib                  0x1100e7707        kfun:kotlin.Exception#(kotlin.String?){} + 95 
        at 2   Janaza.debug.dylib                  0x1100e78d7        kfun:kotlin.RuntimeException#(kotlin.String?){} + 95 
        at 3   Janaza.debug.dylib                  0x11036009f        kfun:kotlinx.coroutines.inside.DiagnosticCoroutineContextException#(kotlin.coroutines.CoroutineContext){} + 175 
        at 4   Janaza.debug.dylib                  0x110331197        kfun:kotlinx.coroutines.inside#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 667 
        at 5   Janaza.debug.dylib                  0x1102bab27        kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 563 
        at 6   Janaza.debug.dylib                  0x1102ae053        kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#inside + 167 
        at 7   Janaza.debug.dylib                  0x11036833f        kfun:kotlinx.coroutines.JobSupport#handleJobException(kotlin.Throwable){}kotlin.Boolean-trampoline + 59 
        at 8   Janaza.debug.dylib                  0x1102c599b        kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#inside + 1227 
        at 9   Janaza.debug.dylib                  0x1102ce3cb        kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#inside + 2447 
        at 10  Janaza.debug.dylib                  0x1102cda03        kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#inside + 755 
        at 11  Janaza.debug.dylib                  0x1102cd50b        kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 451 
        at 12  Janaza.debug.dylib                  0x1102aa277        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Consequence<1:0>){} + 203 
        at 13  Janaza.debug.dylib                  0x11023962f        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Consequence<1:0>){}-trampoline + 99 
        at 14  Janaza.debug.dylib                  0x1100f2ca3        kfun:kotlin.coroutines.native.inside.BaseContinuationImpl#resumeWith(kotlin.Consequence){} + 1295 
        at 15  Janaza.debug.dylib                  0x11023962f                                         0xc353ffffffffffff 0x0 + -4371869338269908993 
Brought on by: kotlin.NullPointerException
    at 0   Janaza.debug.dylib                  0x1100ed823        kfun:kotlin.Throwable#(){} + 75 
    at 1   Janaza.debug.dylib                  0x1100e7693        kfun:kotlin.Exception#(){} + 67 
    at 2   Janaza.debug.dylib                  0x1100e7863        kfun:kotlin.RuntimeException#(){} + 67 
    at 3   Janaza.debug.dylib                  0x1100e7a33        

Right here is my Koin setup:

enjoyable initKoin(config: KoinAppDeclaration? = null) {
    startKoin {
        printLogger(Degree.DEBUG)
        config?.invoke(this)
        modules(
            appModule,
            sharedRepositoryModule,
            viewModelModule
        )
    }
}

My MainViewController:

enjoyable MainViewController() = ComposeUIViewController(
    configure = {
        initKoin()
        Firebase.initialize()
    }
) {
    App()
}

My ViewModelModule:

val viewModelModule = module {
    viewModelOf(::HomeViewModel)
}

My AppModule:

val appModule = module {
single { Firebase.firestore }
single { Firebase.messaging }
single { Firebase.auth }

single { createHttpClient() }

single(named("pray")) { providePrayerCollection(get()) }
single(named("consumer"))  { provideUserCollection(get()) }

singleOf(::OverlayServiceImpl).bind()
singleOf(::BottomSheetServiceImpl).bind()
singleOf(::ToastServiceImpl).bind()
singleOf(::BottomBarServiceImpl).bind()
singleOf(::AlertDialogServiceImpl).bind()

singleOf(::PrayerServiceImpl).bind()
singleOf(::UserServiceImpl).bind()
singleOf(::AuthenticationServiceImpl).bind()

single{
    FirebasePrayerSourceImpl(
        prayerCollection = get(named("pray")),
        firebaseMessaging = get(),
        firebaseAuth = get()

    )
}
single{
    FirebaseUserSourceImpl(
        userCollection = get(named("consumer")),
        firebaseAuth = get()
    )
}
singleOf(::GooglePlacesRepositoryImpl).bind()
singleOf(::PrayersTimeRepositoryImpl).bind()
}

personal enjoyable providePrayerCollection(db: dev.gitlive.firebase.firestore.FirebaseFirestore) =
db.assortment(if (isDebug) "dev_pray" else "pray")

personal enjoyable provideUserCollection(db: dev.gitlive.firebase.firestore.FirebaseFirestore) =
db.assortment("consumer")

Leave a Reply

Your email address will not be published. Required fields are marked *