Hello team, currently migrating to Koin 4.2.0 + Ko...
# koin
r
Hello team, currently migrating to Koin 4.2.0 + Koin compiler plugin 0.4.1 as many others, on a multi-module, Android only, app. I am using DSL only, no annotations. I am stuck on the same
Missing dependency
error on some specific dependencies. It builds and runs fine if i disable the compile safety of the plugin, but actually i want to keep it as it is the main reason why i want to use the compiler plugin. I have those classes :
Copy code
interface CrashLogger {
    fun logException(exception: Throwable)
}

class FirebaseCrashLogger(private val firebaseInstance: FirebaseCrashlytics) : CrashLogger {
    override fun logException(exception: Throwable) { ... }
}
And this in a koin module :
Copy code
single { FirebaseCrashlytics.getInstance() }
single<FirebaseCrashLogger>() bind CrashLogger::class
For what i understand,
single {...}
is in
org.koin.core.module
package, while
single<T>()
is in
org.koin.plugin.module.dsl
package, from the compiler plugin itself. The two seem incompatible because it is where the build gives me this error :
e: [Koin] Missing dependency: com.google.firebase.crashlytics.FirebaseCrashlytics
required by: dsl:com.myapp.crashlogger.FirebaseCrashLogger (parameter ‘firebaseInstance’)
in module: DSL graph
I didn’t find a way to put the
FirebaseCrashlytics.getInstance()
in a
org.koin.plugin.module.dsl.single
as it does not accept a builder block. I did try this, as
create(function: () -> T): T
is from
org.koin.plugin.module.dsl
:
Copy code
single<FirebaseCrashlytics> { create(FirebaseCrashlytics::getInstance) }
But that doesn’t work either. However it works if i use
singleOf(::FirebaseCrashLogger) bind CrashLogger::class
Therefore, the migration to Koin 4.2.0 cannot be fully done and I don’t really know if the compiler performs security checks in these cases.
Ok i found the way to make it work
Copy code
private fun getFirebaseInstance() = FirebaseCrashlytics.getInstance()
module {
    single { create(::getFirebaseInstance) }
    singleFirebaseCrashLogger() bind CrashLogger::class
}