InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
159 stars 43 forks source link

Type org.koin.ksp.generated.KoinDef<dependency> is defined multiple times in a multi-module project #185

Open nsmapp opened 1 week ago

nsmapp commented 1 week ago

Describe the bug A multi-module project is built with an error when extending classes in different modules.

To Reproduce Module 1:

package org.koin.simple.base

open class FooBase {

    val textBase = "text base"
}

Module 2:

package org.koin.simple

@Module
@ComponentScan()
class AModule {}

package org.koin.simple

@Factory()
class FooA: FooBase(){
    val text  = "text a"
}

Module 3:

package org.koin.simple.mb

@Module
@ComponentScan()
class BModule {}

package org.koin.simple.mb

@Factory()
class FooB: FooBase(){
    val text  = "text b"
}

Module app:

package org.koin.sample.di

@Module(includes = [
    AModule::class, BModule::class
])
@ComponentScan("org.koin.sample")
class AppModule

package org.koin.sample

class MainActivity : AppCompatActivity() {

    private val fooA: FooA by inject()
    private val fooB: FooB by inject()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_simple)

        val textField = findViewById<TextView>(R.id.text)
        textField.text = "${fooA.text}\n ${fooB.text}"
    }
}

Result. Project build with error

Caused by: com.android.tools.r8.internal.g: Type org.koin.ksp.generated.KoinDefOrgKoinSimpleBaseFooBase is defined multiple times: /media/nsm/4aeb5859-3b1a-4888-b1b7-6fb9ecd4a3b4/nsm/null2/koin-getting-started/android-annotations/module-a/build/.transforms/6c4b7a04527a57b0b19276e8afa44dda/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/koin/ksp/generated/KoinDefOrgKoinSimpleBaseFooBase.dex, /media/nsm/4aeb5859-3b1a-4888-b1b7-6fb9ecd4a3b4/nsm/null2/koin-getting-started/android-annotations/module-b/build/.transforms/f6d1a675067414cc1abdf61eac29739c/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/org/koin/ksp/generated/KoinDefOrgKoinSimpleBaseFooBase.dex

Expected behavior Build the project without errors

Koin project used and used version (please complete the following information): koin = "4.0.0" koin-annotations = "2.0.0-Beta1" or "1.4.0"

Additional moduleDefinition With library version koin-annotations = "1.3.1" the project is built without errors

marcelpallares commented 1 week ago

Facing the same issue with the same versions in a multi-module project

alaegin commented 15 hours ago

I have the same issue