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

Created on 9 Jul 2020  ·  17Comments  ·  Source: InsertKoinIO/koin

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.

core accepted issue

Most helpful comment

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...)

All 17 comments

I'm still using Kotlin 1.3.72 and received this error.

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

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.

Kotlin 1.4 becomes stable, waiting new release 🌸

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()
}

I have to check & help migration to Kotlin 1.4 for Koin 2.2.0. From what I see here, is the time measurement stuff that are still having problems :/

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

yep could clearly remove this experimental API that keep moving from release to release

👍

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.

Kotlin 1.3.72 + Koin 2.1.5 - OK
Kotlin 1.4 + Koin 2.1.5 - Error

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)

Setting the log level to Level.None also works since the exception happens when Koin needs to log something, completely avoiding java.lang.NoSuchMethodError crash

Kotlin 1.4 + 2.2.0-alpha-1 works well.

Kotlin 1.4 + 2.2.0-alpha-1 works well.

Can confirm - this works for me.

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

This issue has been around since July and has been fixed since August, but hasn't been released yet in November. I know there have been alpha, beta and rc versions that include this fix, but there is no stable release yet. What is standing in the way of this release?

Kotlin 1.4.10 + Koin 2.2.1 - this works for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AHarazim picture AHarazim  ·  3Comments

LukasAnda picture LukasAnda  ·  3Comments

luna-vulpo picture luna-vulpo  ·  4Comments

caleb-allen picture caleb-allen  ·  4Comments

ILAgent picture ILAgent  ·  3Comments