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

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

Open
nsmapp opened this issue Oct 28, 2024 · 9 comments · May be fixed by #206
Open
Labels
important type:issue Something isn't working
Milestone

Comments

@nsmapp
Copy link

nsmapp commented Oct 28, 2024

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
Copy link

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

@alaegin
Copy link

alaegin commented Nov 6, 2024

I have the same issue

@Ph1ll1pp
Copy link

I have the same problem

@marcelpallares
Copy link

As a workaround for anyone facing this (and a very ugly one), I have been copying/pasting the base abstract class and giving it a different name every time I need to use it until this gets resolved.

@nsmapp
Copy link
Author

nsmapp commented Nov 12, 2024

Not a good decision.
As long as there is no annotation solution, you can use the standard Koin module:

val bindModule = module {

    factory { FooA() } bind FooBase::class

    factory { FooB() } bind FooBase::class
}

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

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


@igorbiscanin
Copy link

@arnaudgiuliani Is there maybe any update about this?

@f4bii
Copy link

f4bii commented Dec 2, 2024

Hopefully it will get fixed soon. Until then, I can't update

@arnaudgiuliani arnaudgiuliani added important type:issue Something isn't working labels Dec 6, 2024
@arnaudgiuliani arnaudgiuliani added this to the 2.0 milestone Dec 6, 2024
@arnaudgiuliani
Copy link
Member

Ok, will look at it 👍

@EvgenBES
Copy link

I have the same issue

Sepehr1812 pushed a commit to Sepehr1812/koin-annotations that referenced this issue Jan 8, 2025
Sepehr1812 added a commit to Sepehr1812/koin-annotations that referenced this issue Jan 8, 2025
Sepehr1812 added a commit to Sepehr1812/koin-annotations that referenced this issue Jan 8, 2025
Sepehr1812 added a commit to Sepehr1812/koin-annotations that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
important type:issue Something isn't working
Projects
None yet
8 participants