koin: Does not support Kotlin 1.6.0

Describe the bug Latest koin version produces NoSuchMethodErrors at runtime when using kotlin 1.6.0-RC

To Reproduce Steps to reproduce the behavior:

  1. Add latest stable koin dependency
  2. Use kotlin 1.6.0-RC.
  3. App crashes on startup in 100% cases

Expected behavior The app is able to run without crashing.

Koin project used and used version (please complete the following information): [e.g]: koin version 3.1.2, kotlin 1.6.0-RC

The surest way to get a runtime error is to call a deleted method toDouble() of kotlin.duration that was removed in 1.6.0 by using

startKoin {
            androidContext(applicationContext)
            androidLogger() //This one is causing the crash
            modules(/* blah */)
        }

Stacktrace:

java.lang.NoSuchMethodError: No static method toDouble-impl(JLjava/util/concurrent/TimeUnit;)D in class Lkotlin/time/Duration; or its super classes (declaration of 'kotlin.time.Duration' appears in /data/app/~~RAEJCWfLUZeoA5jJfJMmtA==/com.nek.test.debug-jvqFgZyETecELyVm71SR5A==/base.apk!classes16.dex)
        at org.koin.core.time.MeasureKt.measureDuration(Measure.kt:32)
        at org.koin.core.KoinApplication.modules(KoinApplication.kt:59)
        at org.koin.core.KoinApplication.modules(KoinApplication.kt:50)
        at com.nek.test.TestApplication$onCreate$1.invoke(TestApplication.kt:30)
        at com.nek.test.TestApplication$onCreate$1.invoke(TestApplication.kt:27)
        at org.koin.core.context.GlobalContext.startKoin(GlobalContext.kt:64)
        at org.koin.core.context.DefaultContextExtKt.startKoin(DefaultContextExt.kt:31)
        at com.nek.test.TestApplication.onCreate(TestApplication.kt:27)
    //bunch of junk    

Lesson: do not use experimental APIs

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 78
  • Comments: 27 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Set Koin logger to level Error, as a workaround for the time being

    startKoin {
        androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)
        androidContext(context)
        modules(allModules)
    }

Hi. Any update on this issue? Kotlin 1.6.0 has been released to production and this crash happens, making it impossible to upgrade Kotlin… Thanks.

Koin 3.2.0 will bring Kotlin 1.6

Koin 3.2 is updated for Kotlin 1.6.10 👍

I remember another bug related to this androidLogger before 🧐

Yes, exactly the same happened when Kotlin 1.5 was released: #1076 Duration is nice, but we really should think twice before using experimental API in a public library.

Workaround for Ktor:

install(Koin) {
    slf4jLogger(level = Level.ERROR) //This params are the workaround itself
    modules(
        //specify your modules
    )
}

Set Koin logger to level Error, as a workaround for the time being

    startKoin {
        androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)
        androidContext(context)
        modules(allModules)
    }

That worked. Thanks.

Set Koin logger to level Error, as a workaround for the time being

    startKoin {
        androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)
        androidContext(context)
        modules(allModules)
    }

For those creating their own Logger (for me I created a custom logger wrapping Timber) and not using AndroidLogger make sure to include this as the argument Level to the base Logger class, or anything that avoids Level.INFO and Level.DEBUG.

Koin 3.2.0 will bring Kotlin 1.6

Great news, but note that anyone who still targets SDK 29 won’t be able to update to Koin 3.2.0: Koin 3.1.3+ updates its androidx.activity:activity-ktx dependency to 1.3.1, which requires a minCompileSdk of 30.

Play Store required all app updates to target SDK 30 back in November 2021, but if you’re not using it to publish apps, you’re stuck with this workaround (suggested earlier in this thread):

startKoin {
    androidLogger(Level.ERROR) // default Level.INFO
    ...
}

my case, also get rid of manually set logger for now

startKoin {
            androidLogger(Level.ERROR)
            //logger(object : Logger() {
            //    override fun log(level: Level, msg: MESSAGE) {
            //        Timber.tag("koin(di)").d(msg)
            //    }
            //})
            //...
}

const val KOIN = “3.1.4” const val KOTLIN = “1.6.0” Crash Log: Caused by: o6.c: Could not create instance for [Singleton:‘v3.c’] in Release Build

I remember another bug related to this androidLogger before 🧐