https://kotlinlang.org logo
Join SlackCommunities
Powered by
# koin
  • z

    zsmb

    04/12/2025, 10:47 AM
    When declaring dependencies, the API allows me to specify a nullable type, like
    Copy code
    factory<Flags?> { ... }
    But later on, I can't pass in a nullable type param to a
    get()
    call:
    Copy code
    get<Flags?>()
        ~~~~~~ Type argument is not within its bounds: must be subtype of 'Any'.
    Shouldn't these type parameters have the same bounds?
    w
    • 2
    • 1
  • v

    Vaibhav Jaiswal

    04/14/2025, 1:42 PM
    I was looking into Koin Annotations, and couldnt figure out how is it better then the non-annotation based approach Can anyone help me? Im looking into migrating my codebase to the new Koin Annotations
    k
    a
    • 3
    • 9
  • f

    FKuper

    04/15/2025, 7:15 AM
    Hey everyone, I'm trying to configure Koin with my Compose Multiplatform project (targeting Android and iOS with shared UI). I can't get the iOS build to work.. I've tried following this guide: https://insert-koin.io/docs/quickstart/cmp but it's very vague at the iOS section. I have also looked into the linked code (https://insert-koin.io/docs/quickstart/cmp) and have tried calling initKoin() in both MainViewController's ComposeUIViewController configure parameter and in the iOSApp.swift's init() method... nothing seems to work. When running ./gradlew build im getting:
    Task composeApplinkDebugFrameworkIosArm64 FAILED
    (I can provide exception stack trace's if required) Anyone got any ideas or has struggled with similar issues?
    m
    • 2
    • 4
  • v

    Vaibhav Jaiswal

    04/15/2025, 9:15 AM
    I am trying to migrate to Koin Annotations and facing a problem I have this module in
    commonMain
    Copy code
    @Module
    @ComponentScan("com.medial.app.core")
    internal expect class CorePlatformModule
    
    @Module(includes = [CorePlatformModule::class])
    @ComponentScan("com.medial.app.core")
    class CoreModule {
    
        @Single
        fun connectivity() = Connectivity()
    }
    and these in the android and iOS SourceSet
    Copy code
    @Module
    @ComponentScan("com.medial.app.core")
    internal actual class CorePlatformModule {
    
        @Single
        fun amplitude(context: Context) = Amplitude(
            Configuration(
                apiKey = AppConfig.AMPLITUDE_API_KEY,
                context = context.applicationContext,
                locationListening = true,
                identifyBatchIntervalMillis = 0,
                defaultTracking = DefaultTrackingOptions(
                    sessions = true,
                    deepLinks = true,
                    appLifecycles = true,
                    screenViews = false
                )
            )
        )
    }
    Copy code
    @Module
    @ComponentScan("com.medial.app.core")
    internal actual class CorePlatformModule {
    
        @Single
        fun amplitude() = Amplitude.instance().apply {
            initializeApiKey(AppConfig.AMPLITUDE_API_KEY)
            defaultTracking = AMPDefaultTrackingOptions().apply {
                sessions = true
                deepLinks = true
                appLifecycles = true
                screenViews = true
            }
        }
    }
    Now when i try to run my app, i get this error > Expect declaration
    module
    doesn't match actual
    module
    because parameter types are different Does Anyone know, why this error is showing up ?
  • a

    Antonis Radz

    04/15/2025, 9:38 AM
    hey after updating to latest kotlin and ksp version in multiplatform project I am getting build time error:
    Copy code
    * Exception is:
    org.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':shared:kspCommonMainKotlinMetadata' (type 'KspAATask').
      - Gradle detected a problem with the following location: '..../shared/build/generated/ksp/metadata/commonMain/kotlin'.
        
        Reason: Task ':shared:kspDebugKotlinAndroid' uses this output of task ':shared:kspCommonMainKotlinMetadata' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
        
        Possible solutions:
          1. Declare task ':shared:kspCommonMainKotlinMetadata' as an input of ':shared:kspDebugKotlinAndroid'.
          2. Declare an explicit dependency on ':shared:kspCommonMainKotlinMetadata' from ':shared:kspDebugKotlinAndroid' using Task#dependsOn.
          3. Declare an explicit dependency on ':shared:kspCommonMainKotlinMetadata' from ':shared:kspDebugKotlinAndroid' using Task#mustRunAfter.
    Any ideas how to fix it?
    ksp = "2.1.0-1.0.29"
    kotlin = "2.1.0"
    These lines are causing it:
    Copy code
    dependencies {
        add("kspCommonMainMetadata", libs.koin.ksp.compiler)
        add("kspAndroid", libs.koin.ksp.compiler)
        add("kspIosX64", libs.koin.ksp.compiler)
        add("kspIosArm64", libs.koin.ksp.compiler)
        add("kspIosSimulatorArm64", libs.koin.ksp.compiler)
    }
    
    project.tasks.withType(KotlinCompilationTask::class.java).configureEach {
        if (name != "kspCommonMainKotlinMetadata") {
            dependsOn("kspCommonMainKotlinMetadata")
        }
    }
    Thanks in advance!
    f
    • 2
    • 7
  • p

    Pablo

    04/16/2025, 12:23 PM
    is there any way to restart Koin? I'm facint the same issue than this guy, some values of my Koin singletons changes so I need to reload them: https://stackoverflow.com/questions/63290183/android-koin-how-to-tell-koin-that-a-single-dependency-should-be-reinitialized unloading and reloading the modules doesn't work, as it is a singleton, and seems that Koin still keeps the cached singleton in memory, and doesn't unload/reload it
    Copy code
    unloadKoinModules(networkModule)
    loadKoinModules(networkModule)
    do exist any solution for this? any solution that doesn't implies adding complexity like factories that embeds a singleton and checks if a variable has changed and then returns another singleton, I don't like that approach. I'm considering restarting the entire application, but seems that android doesn't offers a 100% supported way to achieve this. Something like
    unloadKoinModulesIncludingSingletons(networkModule)
    will be perfect. The solution proposed by that guy is not posted in the link anymore, and the alternative of doing
    val api: InstanceApi = getKoin().get()
    is not applicable in my case. I tryed doing stopKoin and startKoin again, but the modules are not being reloaded, don't know why.
    s
    • 2
    • 1
  • b

    bartek.t

    04/17/2025, 3:11 PM
    Is there a way to persist scope for the time that Composable screen exist in navigation back stack entry with usage of current api?
  • d

    dhia chemingui

    04/18/2025, 7:39 AM
    Hi about the new plugin I cant understand this warnings
    m
    • 2
    • 1
  • e

    Eduardo Ruesta

    04/18/2025, 1:56 PM
    Hey team! i have a Compose Multiplatform project! using Koin:4.0.3, on Android is working fine but on iOS the app crash
    Copy code
    Uncaught Kotlin exception: org.koin.core.error.InstanceCreationException: Could not create instance for '[Factory: 'com.bebi.app.viewmodel.MediaOpinionViewModel']'
    Any thought?
    Copy code
    /**
     * Common Koin module for the application
     */
    val appModule = module {
        // Database
        single { get<DatabaseProvider>().getDatabase() }
        single { get<AppDatabase>().mediaOpinionDao }
    }
    
    val dataModule = module {
        factoryOf(::RoomMediaOpinionRepository)
    }
    
    val viewModelModule = module {
        viewModelOf(::MediaOpinionViewModel)
        viewModelOf(::MediaDetailViewModel)
    }
    
    expect interface DatabaseProvider {
        fun getDatabase(): AppDatabase
    }
    
    expect val nativeModule: Module
    
    fun initKoin(config: KoinAppDeclaration? = null) {
        startKoin {
            config?.invoke(this)
            modules(appModule, dataModule, viewModelModule, nativeModule)
        }
    }
    👀 1
    kodee happy 1
  • u

    Ume Channel

    04/18/2025, 6:58 PM
    Hello, i think there's error in koin in android when I use single - in the Composable function it's only run once in LaunchEffect function when I navigate to other screen if I navigate back however if i use factory it will run everytime when I navigate. I thought that single is for init instance only why affect LaunchEffect? So I change it to factory
  • d

    dhia chemingui

    04/19/2025, 9:36 AM
    okay if you navigate back the launched effect callback will run even if the state does not change . Can you explain more your problem
    u
    • 2
    • 11
  • b

    Bruce Xia

    04/20/2025, 3:46 AM
    hello, the koin document mentions activityScope, however it's not available, I'm using koin 4.0.3 with following dependencies, is it defined iin other module?
    Copy code
    // Koin
    implementation "io.insert-koin:koin-core:${koinVersion}"
    implementation "io.insert-koin:koin-android:${koinVersion}"
    implementation "io.insert-koin:koin-androidx-compose:${koinVersion}"
    implementation("io.insert-koin:koin-compose:${koinVersion}")
    implementation("io.insert-koin:koin-compose-viewmodel:${koinVersion}")
  • s

    Slackbot

    04/25/2025, 1:08 AM
    This message was deleted.
    y
    • 2
    • 1
  • k

    Kev

    04/26/2025, 7:54 AM
    Hello, i'm struggling with Koin injection. I have the following code with the following error:
    Copy code
    fun Routing.leaderboard() {
    
        val service by inject<UserService>()
    
        get<LeaderboardResource.Top100> {
            service.getUserLeaderboard().map { leaderboard ->
                leaderboard.map { Leaderboard(it.first, it.second) }
            }.respond(HttpStatusCode.OK)
        }
    }
    a
    • 2
    • 2
  • s

    stuebingerb

    04/26/2025, 11:18 AM
    Hello, is there an approximate ETA for koin 4.1.0? Or would you consider ktor3 support already stable in the current beta?
    👍 1
    a
    • 2
    • 1
  • j

    Jonathan

    04/29/2025, 1:26 PM
    Does Koin annotation support auto finding interface implementations? I would, in theory, like to have an interface implemented natively on both Android and iOS and automatically attached to a
    @Module class.
    The Koin documentation only shows this structure for
    expect/actual
    classes.
    a
    • 2
    • 1
  • p

    Pablo

    04/29/2025, 1:47 PM
    I have a data class that must be shared between all the app. That dataclass value is get in a viewmodel, using a corutine, etc... How can I share that between the app with Koin? I found that you can change a Koin single value doing this: getKoin().setProperty("ProjectConfig", newValue). I don't know if it works, I didn't test it. Before I wanna know if this is a good practice or not. Or maybe alternatives.
    w
    r
    • 3
    • 8
  • t

    Talha

    04/30/2025, 4:52 PM
    Is it possible to use Koin Annotations in a KMP module's
    commonTest
    sourceset to provide dependencies and define modules? I can't find any documentation or examples of annotations being used to provide classes in tests?
    p
    • 2
    • 2
  • t

    Thierry Kh

    05/04/2025, 12:12 AM
    Hello. Isn't it possible to declare a component that has more more than 22 dependencies with singleOf(::ClassA) ?
    Copy code
    public inline fun <reified R, reified T1, reified T2, reified T3, reified T4, reified T5, reified T6, reified T7, reified T8, reified T9, reified T10, reified T11, reified T12, reified T13, reified T14, reified T15, reified T16, reified T17, reified T18, reified T19, reified T20, reified T21, reified T22> org.koin.core.module.Module.factoryOf(crossinline constructor: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) -> R, noinline options: (org.koin.core.definition.BeanDefinition<R>.() -> kotlin.Unit)? /* from: org.koin.core.module.dsl.DefinitionOptions<R>? */ = COMPILED_CODE): org.koin.core.definition.KoinDefinition<R> { /* compiled code */ }
    ✅ 1
    🤢 2
    p
    • 2
    • 5
  • r

    Ruben Quadros

    05/04/2025, 2:22 PM
    Hey everyone, I cannot seem to get koin annotations working with expect/actual classes. The sample app is here. The setup is very simple:
    Copy code
    @Single
    expect class MyClass() (Common)
    
    @Single
    actual class MyClass actual constructor() (Android/ios)
    I have tried multiple variations - expect actual module, try defining the dependency in the module but nothing seems to work. What is the correct way for this? Thanks!
    p
    • 2
    • 4
  • i

    Idris Ocasio

    05/04/2025, 5:08 PM
    Hello! I'm building a compose multiplatform app, I am trying to use gitlive's firebase dependencies and the app seems to crash whenever I try to provide firebase dependencies in my koin injected classes. Is what I'm trying to do achievable?
    ✅ 1
    p
    • 2
    • 2
  • a

    arnaud.giuliani

    05/05/2025, 10:21 AM
    Hello all 👋 I propose to merge koin-ktor and koin-ktor3 in current 4.1 - https://github.com/InsertKoinIO/koin/issues/2186
    👍 7
    👍🏻 1
  • a

    arnaud.giuliani

    05/05/2025, 10:21 AM
    your feedback is welcome
  • a

    Arsildo Murati

    05/07/2025, 1:55 PM
    Hi, when trying to upload a build to the playstore with koin-bom = "4.1.0-Beta8" I am getting
    Your APK or Android App Bundle is using permissions that require a privacy policy: (android.permission.READ_PHONE_STATE).
    😮 1
    🤔 1
    ✅ 1
    a
    z
    m
    • 4
    • 37
  • j

    Jimmy Nelle

    05/09/2025, 8:47 AM
    Hello Guys, I'm using Koin 4.1.0-Beta8 in my Compose Multiplatform app with
    Copy code
    KoinMultiplatformApplication
    and getting the whole time the following error only on iOS:
    Copy code
    [INFO] [Koin] Started 4 definitions in 0.007 ms
    Uncaught Kotlin exception: kotlin.IllegalStateException: Koin context has not been initialized in rememberKoinApplication
    Check the 🧵 for more context
    👀 1
    a
    • 2
    • 14
  • g

    Guyaume Tremblay

    05/09/2025, 2:45 PM
    Hi! I'm migrating a KMP project to Koin 4 and Koin-Annotation 2 but the definition of my module moved from
    commonMain
    to
    androidMain
    ! In fact, there is still a
    defaultModule
    in the
    commonMain
    with 2
    @Factory
    . All of my
    @Single
    is now in my custom Module in
    build/generated/ksp/android/androidDebug/kotlin/org.koin.ksp.generated
    . I tried koin-annotations 2.0.1-RC1 seeing this PR :
    Fix - Fix all kmp generation from commonMain to native side by @arnaudgiuliani in #258
    but still the same. This project doesn't have any module, singleton or factory on the platform side. Do you have any idea of what is happening?
    a
    • 2
    • 14
  • p

    Piotr Prus

    05/11/2025, 5:48 AM
    Hi! I have a problem with using annotations on functions that have a few parameters of the same type. I tried to used
    named
    and
    property
    but that does not work.
    Copy code
    @Single
        @Named("httpLoggingInterceptor")
        fun provideLoggingInterceptor(): Interceptor =
            HttpLoggingInterceptor().apply {
                level = HttpLoggingInterceptor.Level.BODY
            }
    
        @Single
        @Named("myOkHttpClient")
        fun providePublicHttpClient(
            authenticator: Authenticator,
            @Property("addHeadersInterceptor") addHeadersInterceptor: Interceptor,
            @Property("httpLoggingInterceptor") logInterceptor: Interceptor,
            @Property("forbiddenInterceptor") forbiddenInterceptor: Interceptor
        ): OkHttpClient =
    The generated code in the thread 🧵
    a
    • 2
    • 7
  • t

    Tower Guidev2

    05/12/2025, 6:36 AM
    Hi anyone assist me in understanding the difference between
    org.koin.android.ext.android.inject
    &
    org.koin.core.component.inject
    please? and which one i should be using in my android koin 4 application. does it matter which one i use?
    a
    • 2
    • 5
  • p

    Pablo

    05/12/2025, 8:21 AM
    can I use Koin with a glance widget? how?
    p
    • 2
    • 1
  • a

    arnaud.giuliani

    05/12/2025, 5:32 PM
    We are reaching the end of the beta phases for #Koin 4.1 🔥 We finally settled on integrating the new Compose 1.8 and Lifecycle library 2.9 in Koin. Thanks Màrton & Ivan for your help! 🙏 You can find the latest changes in the KotlinConf app already on the repo (https://github.com/JetBrains/kotlinconf-app) You can start playing with 4.1.0-Beta11 👍 I'm still working on last Ktor 3.2 integrations. A patch for Koin Annotations 2.0 will follow soon to help adjust with the new koin-core-annotations artifact. https://github.com/InsertKoinIO/koin/releases/tag/4.1.0-Beta11 Stay tuned ✌️
    🎉 6
    koinscroll 3