InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.98k stars 710 forks source link

Seems like Koin Crash Again on androidContext 3.5.1 #1735

Open Morons opened 9 months ago

Morons commented 9 months ago
java.lang.NoSuchMethodError: No static method loadModules$default(Lorg/koin/core/Koin;Ljava/util/List;ZILjava/lang/Object;)V in class Lorg/koin/core/Koin; or its super classes (declaration of 'org.koin.core.Koin' appears in /data/app/~~OPFOrpTtKlxVp_pMshHQ2w==/za.co.zone.cupio-EEanIvolXITNVmqkA3vjHg==/base.apk!classes19.dex)
startKoin { 
    androidContext(this@Application)

Gradle

val koinBom = platform(libs.koin.bom)
implementation(koinBom)
implementation(libs.bundles.koin)
koin-bom = "3.5.1"

koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-ktor = { module = "io.insert-koin:koin-ktor"}
koin-compose = { module = "io.insert-koin:koin-compose"}
koin-android = { module = "io.insert-koin:koin-android"}
koin-logger-slf4j = { module = "io.insert-koin:koin-logger-slf4j"}
koin-android-compat = { module = "io.insert-koin:koin-android-compat"}
koin-androidx-Compose = { module = "io.insert-koin:koin-androidx-compose"}
koin-androidx-navigation = { module = "io.insert-koin:koin-androidx-navigation"}
koin-androidx-workmanager = { module = "io.insert-koin:koin-androidx-workmanager"}

koin = ["koin-core", "koin-ktor", "koin-compose", "koin-android", "koin-logger-slf4j", "koin-android-compat",
    "koin-androidx-Compose", "koin-androidx-navigation", "koin-androidx-workmanager"]
arnaudgiuliani commented 9 months ago

Seems like a classpath problem. Do you have multiple versions elsewhere?

pedrofsn commented 8 months ago

Run ./gradlew dependencies and check if are some library using koin (with different version of 3.5.1). If you found something you will need to update them.

hoangchungk53qx1 commented 8 months ago
I had the same problem, temporary fix
class XXXApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    startKoin {
      androidLogger()
      modules(
        module {
          single { this@XXXApplication } binds arrayOf(Context::class,Application::class)
        }
      )
    }
  }

}
arnaudgiuliani commented 8 months ago

why don't you use androidContext() in your Koin config?

hoangchungk53qx1 commented 8 months ago

why don't you use androidContext() in your Koin config?

i will be crash, I tried that and was told that the module has not been provided for androidContext.

https://github.com/InsertKoinIO/koin/issues/1764

arnaudgiuliani commented 8 months ago

java.lang.NoSuchMethodError: No static method

keeps to be a setup/classpath problem here. Can you use directly implementation(project( ))?

mrcsxsiq commented 6 months ago

Same problem here. I'm using koin version 3.5.3

This not work:

startKoin {
     androidLogger()
     androidContext(this@MainApplication)
     modules(MainModule.instance)
}

Using @hoangchungk53qx1's suggestion works:

startKoin {
     androidLogger()
     module {
          single { this@MainApplication } binds arrayOf(Context::class, Application::class)
     }
     modules(MainModule.instance)
}
arnaudgiuliani commented 6 months ago

What is curious is that behind the scene, Koin is making the binds for you 🤔

hoangchungk53qx1 commented 6 months ago

What is curious is that behind the scene, Koin is making the binds for you 🤔

I think something went wrong when publishing the new version.

arnaudgiuliani commented 6 months ago

any help to create a sample app to reproduce this? 🙏