Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not support Kotlin 1.6.0 #1188

Closed
Nek-12 opened this issue Oct 21, 2021 · 27 comments
Closed

Does not support Kotlin 1.6.0 #1188

Nek-12 opened this issue Oct 21, 2021 · 27 comments

Comments

@Nek-12
Copy link

Nek-12 commented Oct 21, 2021

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

@franciscofranco
Copy link

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.

@SerggioC
Copy link

same thing.
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/..
Do I need to trash Koin or downgrade Kotlin?

@victorlapin
Copy link

victorlapin commented Nov 16, 2021

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

@SerggioC
Copy link

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.

@arnaudgiuliani
Copy link
Member

Yes sorry, use this workaround for now.

@jemshit
Copy link

jemshit commented Dec 3, 2021

I remember another bug related to this androidLogger before 🧐

@TreeFrogApps
Copy link

TreeFrogApps commented Dec 4, 2021

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.

@gmk57
Copy link

gmk57 commented Dec 7, 2021

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.

@jiurchuk
Copy link

jiurchuk commented Dec 13, 2021

Workaround for Ktor:

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

@EGFireball
Copy link

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

This works ! Thanks !

@muhrifqii
Copy link

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

@carmelogallo
Copy link

carmelogallo commented Dec 27, 2021

Hey guys, any news on this?

Using KMM I couldn't find a way to fix this crash. Even creating an ErrorLogger did not work for me.

startKoin {
    logger(ErrorLogger())
    appDeclaration?.invoke(this)
    modules(koinModules)
}

class ErrorLogger : Logger(Level.ERROR) {
    override fun log(level: Level, msg: MESSAGE) {
        println(msg)
    }
}

Any help?

@athulcek
Copy link

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

@lotdrops
Copy link

lotdrops commented Jan 6, 2022

@cikpis I got it working in KMM in two ways:

  1. With an expect logger and actual implementations:
    Common: expect val koinLogger: KoinApplication.() -> Unit
    Android:
actual val koinLogger: KoinApplication.() -> Unit = {
    androidLogger(level = Level.ERROR)
}

iOS: actual val koinLogger: KoinApplication.() -> Unit = {}
Then, in the startKoin block you run koinLogger().

  1. Providing platform app declarations to the koin init in shared:
internal fun initKoin(appDeclaration: KoinAppDeclaration = {}) =
    startKoin {
        appDeclaration()
        modules(
            // your modules...
        )
    }

Also in shared:

fun initKoinAndroid(appDeclaration: KoinAppDeclaration = {}) =
    initKoin(appDeclaration)

Then in the app module in Android, in MyApplication/BaseApplication:

initKoinAndroid() {
            androidLogger(Level.ERROR)
            androidContext(this@MyApplication)
            // optional: modules(appModule)
        }

@carmelogallo
Copy link

Thanks @lotdrops, I'll give it a try and keep you posted.

@hoc081098
Copy link

any release for kotlin 1.6.0?

@arnaudgiuliani
Copy link
Member

Koin 3.2.0 will bring Kotlin 1.6

jaredstockton added a commit to BottleRocketStudios/Android-ArchitectureDemo that referenced this issue Jan 25, 2022
* Updating Kotlin to 1.6.10 required updating some Compose dependencies to the next RC versions (which support a matching version of Kotlin)
* Add support to use `ksp` for Moshi code-gen instead of using `kapt`. `kapt` will still be required as long as DataBinding is used in the project (see https://twitter.com/yigitboyar/status/1447408905240264704)
* Workaround koin crash on launch caused by Kotlin 1.6.x update: InsertKoinIO/koin#1188 (comment)
* Add additional unit test coverage in `:data` to bring coverage back up above 40%
* Update other dependencies
jaredstockton added a commit to BottleRocketStudios/Android-ArchitectureDemo that referenced this issue Jan 25, 2022
* Updating Kotlin to 1.6.10 required updating some Compose dependencies to the next RC versions (which support a matching version of Kotlin)
* Add support to use `ksp` for Moshi code-gen instead of using `kapt`. `kapt` will still be required as long as DataBinding is used in the project (see https://twitter.com/yigitboyar/status/1447408905240264704)
* Workaround koin crash on launch caused by Kotlin 1.6.x update: InsertKoinIO/koin#1188 (comment)
* Add additional unit test coverage in `:data` to bring coverage back up above 40%
* Update other dependencies
@adhirajsinghchauhan
Copy link

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.

Goes back even further; Kotlin 1.4: #847

@adhirajsinghchauhan
Copy link

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

@gmk57
Copy link

gmk57 commented Jan 27, 2022

anyone who still targets SDK 29 won't be able to update to Koin 3.2.0

What prevents you from having compileSdk 30 (or 31) and targetSdk 29 (or even lower)? They are completely different attributes. And despite old posts about library's targetSdk getting merged into resulting manifest, that doesn't seem to be the case nowadays.

Edit: Manifest merging rules clearly state that "attributes in the <uses-sdk> element always use the value from the higher-priority manifest" and "build configurations from the build.gradle file override any corresponding attributes in the merged manifest file".

@arnaudgiuliani
Copy link
Member

Koin 3.2 is updated for Kotlin 1.6.10 👍

@carmelogallo
Copy link

@arnaudgiuliani great news! Do you guys know already when will it be released?

@JyotimoyKashyap
Copy link

Workaround for Ktor:

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

Thanks this works for me.

@majidebraa
Copy link

Koin 3.2 is updated for Kotlin 1.6.10 👍

3.2.0-beta-1 still does not work for me with Kotlin 1.6.10 and the app gets crash and generates these errors for all module injections:
org.koin.core.error.InstanceCreationException: Could not create an instance for [Factory:
org.koin.core.error.InstanceCreationException: Could not create instance for [Singleton:

@victorlapin
Copy link

Koin 3.2 is updated for Kotlin 1.6.10 👍

3.2.0-beta-1 still does not work for me with Kotlin 1.6.10 and the app gets crash and generates these errors for all module injections: org.koin.core.error.InstanceCreationException: Could not create an instance for [Factory: org.koin.core.error.InstanceCreationException: Could not create instance for [Singleton:

That's weird, because I've updated to 3.2.0-beta-1 in several different projects, and all worked fine. Maybe check your other artifacts, for example, DBInspector is using Koin as well, and it's linked with 3.1.4 (we've had to temporarily exclude it from our project)

@alinegtcl
Copy link

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

This works for me! Thanks!

@Basitali12
Copy link

Basitali12 commented May 15, 2023

if any one facing issue like: 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

so you need to change "androidLogger()" to androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)

koin = startKoin {
// Koin Android logger

        androidLogger(if (BuildConfig.DEBUG) Level.ERROR else Level.NONE)
        //inject Android context
        androidContext(this)
        modules(modules)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests