koin: After updating Koin 2.1.6 version I Got crash like. java.lang.NoSuchMethodError: No virtual method elapsedNow()D in class Lkotlin/time/TimeMark; or its super classes (declaration of 'kotlin.time.TimeMark' appears ....

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/my.app.id-IIFeKPZKJaPEihLziq4cTg==/base.apk!classes3.dex)
    at org.koin.core.time.MeasureKt.measureDuration(Measure.kt:36)
    at org.koin.core.KoinApplication.modules(KoinApplication.kt:60)
    at my.app.id.App$onCreate$1.invoke(App.kt:51)
    at my.app.id.App$onCreate$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 my.app.id.App.onCreate(App.kt:40)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1182)
    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)`

in App.kt (Application) class in onCreate method

`startKoin {
            // use AndroidLogger as Koin Logger - default Level.INFO
            androidLogger()

            // use the Android context given there
            androidContext(this@App)

            // load properties from assets/koin.properties file
            androidFileProperties()

            // module list
            modules(listOf(module1, module2, module3))
        }`

UODATE: Similar issue appeared on 3.0.1 version

About this issue

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

Commits related to this issue

Most upvoted comments

@JosephSanjaya we have the answer in this other Issue.

1 - You can migrate the logger from androidLogger() to androidLogger(Level.ERROR) by @dummyco

2 - You can use the val inside KoinApplication like this:

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

by @mannodermaus

Looks like this issue has shown up again. I am not using Koin directly

I am experiencing this issue too, using 3.0.1. The fix might have landed in 2.x but not in 3.x? @mcnarek do you care to re-open this issue?

Replacing

        initKoin {
            androidLogger()

with

        initKoin {
            androidLogger(Level.ERROR) // Or any other level I guess

fixed it for me

when using kotlinx-datetime this issue happened in Android platform

androidLogger(Level.ERROR)

solve this problem

Personally, I was using different versions of koin for KMM project I was working on. After changing the koin version to 3.1.1 for all modules (android and common) removed the error for me.

@JosephSanjaya we have the answer in this other Issue.

1 - You can migrate the logger from androidLogger() to androidLogger(Level.ERROR) by @dummyco

2 - You can use the val inside KoinApplication like this:

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

by @mannodermaus

I am using a library that has a Koin dependency and this crashes whenever trying to run code from their framework. Is there any way to work around this issue if Koin is used by a library? I don’t have any direct dependencies to Koin in my application so I am not the one calling startKoin.

In my case, this issue was caused by multiple JAR files in the classpath with different versions. This was the warning issued by the building procedure:

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /*/.gradle/caches/transforms-2/files-2.1/4487fd127f7a08e89641cd654045a160/jetified-kotlin-stdlib-jdk8-1.4.30.jar (version 1.4)
    /*/.gradle/caches/transforms-2/files-2.1/e126886026a6667eeb50243be13308b3/jetified-kotlin-stdlib-jdk7-1.4.30.jar (version 1.4)
    /*/.gradle/caches/transforms-2/files-2.1/a1c4be33b69edf7445c8b8a868539716/jetified-kotlin-reflect-1.4.30.jar (version 1.4)
    /*/.gradle/caches/transforms-2/files-2.1/77ad8de65641e29d0ce63bef5c066de6/jetified-kotlin-stdlib-1.5.10.jar (version 1.5)
    /*/.gradle/caches/transforms-2/files-2.1/4fad198518f8113eba0ffc5a9066173f/jetified-kotlin-stdlib-common-1.5.10.jar (version 1.5)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

I verified that this was the issue by forcing the version resolution of org.jetbrains.kotlin:kotlin-stdlib to 1.4.30.

implementation("org.jetbrains.kotlin:kotlin-stdlib") {
    version {
        strictly("1.4.30")
    }
}

Maybe this piece of information could be useful.