koin: [Crash] Koin Logger Measure and Kotlin EAP 1.4-M3

Describe the bug This is just a heads up on Koin and Kotlin EAP 1.4-M3.

After upgrading to Kotlin EAP 1.4-M3 (from previous Kotlin EAP 1.4-M2) when launching the app a NoSuchMethodException exception is thrown due to the elapseNow() experimental method.

Full exception below:

    java.lang.NoSuchMethodError: No virtual method elapsedNow()D in class Lkotlin/time/TimeMark; or its super classes (declaration of 'kotlin.time.TimeMark' appears in /data/app/io.petros.movies-u-dzv9wkMPKfx19uLVQWyg==/base.apk)
        at org.koin.core.time.MeasureKt.measureDuration(Measure.kt:36)
        at org.koin.core.KoinApplication.modules(KoinApplication.kt:60)
        at io.petros.movies.app.App$initKoin$1.invoke(App.kt:45)
        at io.petros.movies.app.App$initKoin$1.invoke(App.kt:23)
        at org.koin.core.context.ContextFunctionsKt.startKoin(ContextFunctions.kt:39)
        at org.koin.core.context.ContextFunctionsKt.startKoin$default(ContextFunctions.kt:35)
        at io.petros.movies.app.App.initKoin(App.kt:42)
        at io.petros.movies.app.App.onCreate(App.kt:34)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1189)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6460)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

This is due to the fact that my app is using androidLogger(), which default to a Koin log level of Level.INFO and as such when modules are build the duration is measured, which crashes the app. To overcome this I disabled logging for now, but it will be good if that get fixed so that I can enable it again.

To Reproduce Steps to reproduce the behavior:

  1. Use Kotlin EAP 1.4-M3 as a dependency in your app (or project)
  2. During Koin init start with default logging enabled (Level.INFO)
  3. Launch your app (or project)
  4. See error

Expected behavior I except the app to not crash.

Koin project used and used version (please complete the following information): org.jetbrains.kotlin:kotlin-stdlib:1.4-M3 org.koin:koin-core:2.1.6 org.koin:koin-android:2.1.6 org.koin:koin-androidx-viewmodel:2.1.6

Additional moduleDefinition No additional moduleDefinition.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 46
  • Comments: 26 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Would be nice to release 2.1.7 with just this fixed. This is the only way that’s stopping my team from updating to Kotlin 1.4. (Sure, there are workarounds, but…)

I’m facing the same issue with 1.4.0-rc too. ❗ Temporary workaround: Migrate from androidLogger() to androidLogger(Level.ERROR)

Kotlin 1.4 + 2.2.0-alpha-1 works well.

Kotlin 1.4 becomes stable, waiting new release 🌸

same issue kotlin 1.5.0 + koin 3.0.1

androidLogger(Level.INFO) crashed

Same problem here, updating to stable Kotlin 1.4 bricks loading the modules because the still experimental time API seems to have changed something under the hood, I’m using a modified copy of modules now that doesn’t use the time API to fix this.

@arnaudgiuliani Would have been nice to know upfront that Koin is using unstable experimental API under the hood, and in such a core code path even - silently opting in to the ExperimentalTime annotation seems like a questionable choice here

I got this crash after updating to stable Kotlin 1.4.0 while everything worked fine before on 1.3.72 Kotlin and 2.1.6 Koin.

Release Candidate version 2.2.0-rc-3 has this issue fixed

FWIW the encapsulated functionality of modules() is public, so you’d also be able to work around this by inlining the work of that method in your own setup. This way, there is no need to lose all info-level logging going forward.

// Before:
startKoin {
    androidLogger()
    androidContext(this@MyApplication)

    modules(koinModules)
}

// After:
startKoin {
    androidLogger()
    androidContext(this@MyApplication)

    // TODO Await fix for Koin and replace the explicit invocations
    //  of loadModules() and createRootScope() with a single call to modules()
    //  (https://github.com/InsertKoinIO/koin/issues/847)
    koin.loadModules(koinModules)
    koin.createRootScope()
}

Kotlin 1.4.10 + Koin 2.2.1 - this works for me.

Kotlin 1.4 + 2.2.0-alpha-1 works well.

Can confirm - this works for me.

I’m facing the same issue with 1.4.0-rc too. ❗ Temporary workaround: Migrate from androidLogger() to androidLogger(Level.ERROR)

I am facing the same issue with koinVersion = ‘2.1.6’.

This workaround is working btw.