Skip to content

Native framework link fails with "IrSimpleFunctionSymbolImpl is already bound": @Module(includes = …) re-declares the included modules' componentscan hints (1.2.2, 1.2.3) #146

Open

Description

@JJSarrasin

Generated by Claude:

Summary

Since 1.2.2, a KMP library whose @Module has includes = [...] pointing at @ComponentScan modules from other Gradle modules re-declares the componentscan_* hints of those modules in its own klib. The same hint is then declared in two klibs, and the Kotlin/Native link of the final framework fails with IrSimpleFunctionSymbolImpl is already bound.

Every compileKotlinIosSimulatorArm64 task passes; only linkDebugFrameworkIosSimulatorArm64 fails. The same sources link fine with 1.2.1. The 1.2.3 fix for #144 does not change this case.

Environment

  • koin-compiler-plugin 1.2.2 and 1.2.3: link fails. 1.2.1: link OK.
  • koin / koin-annotations 4.2.2
  • Kotlin 2.4.21 (the plugin logs that it proceeds with the 2.4.20 adapter)
  • Gradle 9.8.2, AGP 9.5.0, Compose Multiplatform 1.12.0
  • Target iosSimulatorArm64, dynamic framework (isStatic = false)
  • compileSafety = false in every module

Module layout

Each module below is its own Gradle module with the compiler plugin applied.

// :core:base
@Module @ComponentScan("com.example.core.base") class BaseModule
// :core:model, :core:resources, :core:network, :core:database: same shape

// :core:data
@Module(includes = [NetworkModule::class, DatabaseModule::class])
@ComponentScan("com.example.core.data")
class DataModule

// :core:viewmodel
@Module(includes = [BaseModule::class, ResourcesModule::class, ModelModule::class, DataModule::class])
@ComponentScan("com.example.core.viewmodel")
class ViewmodelModule

The app framework (:app:mobile:shared, baseName = "Cmp") depends on all of them and exports :core:base, :core:model, :core:resources, :core:viewmodel and :core:ui.

Error

> Task :app:mobile:shared:linkDebugFrameworkIosSimulatorArm64 FAILED
e: Compilation failed: IrSimpleFunctionSymbolImpl is already bound. Signature: org.koin.plugin.hints/componentscan_com_example_core_base_di_BaseModule_single|componentscan_com_example_core_base_di_BaseModule_single(com.example.core.base.interfaces.BiometricHelper;com.example.core.base.interfaces.IBiometricHelper){}[0]. Owner: FUN name:componentscan_com_example_core_base_di_BaseModule_single visibility:public modality:FINAL <> (contributed:com.example.core.base.interfaces.BiometricHelper, binding0:com.example.core.base.interfaces.IBiometricHelper) returnType:kotlin.Unit

 * Compiler version: 2.4.21
 * Output kind: FRAMEWORK

e: java.lang.IllegalStateException: IrSimpleFunctionSymbolImpl is already bound. Signature: org.koin.plugin.hints/componentscan_com_example_core_base_di_BaseModule_single|…
	at org.jetbrains.kotlin.ir.symbols.impl.IrSymbolBase.bind(IrSymbolImpl.kt:68)
	at org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl.<init>(IrFunctionImpl.kt:70)
	at org.jetbrains.kotlin.ir.declarations.IrFactory.createSimpleFunction(IrFactory.kt:212)
	at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrFunction(IrDeclarationDeserializer.kt:596)
	at org.jetbrains.kotlin.backend.common.serialization.IrFileDeserializerImpl.deserializeDeclaration(IrFileDeserializer.kt:81)
	at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer.deserializeReachableDeclarations(BasicIrModuleDeserializer.kt:169)
	at org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker.deserializeAllReachableTopLevels(KotlinIrLinker.kt:176)
	at org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator.generateUnboundSymbolsAsDependencies(ExternalDependenciesGenerator.kt:39)
	…

BiometricHelper is a @Single class BiometricHelper : IBiometricHelper declared in iosMain of :core:base and picked up by the commonMain @ComponentScan. The linker stops at this first collision; the duplicated hints listed below have the same shape.

What the klibs declare

Counted with klib dump-ir-signatures, "Declared signatures" section, on the iosSimulatorArm64 klibs.

With 1.2.3:

klib hints of an included module declared again identical to the owner's klib
:core:viewmodel BaseModule × 14 same count as :core:base (14), the reported signature among them
:core:viewmodel ModelModule × 3 3 / 3
:core:viewmodel ResourcesModule × 1 1 / 1
:core:viewmodel DataModule × 71 58 / 58 of :core:data's own, plus 13 for :core:network / :core:database types under the DataModule prefix
:core:data NetworkModule × 5 5 / 5
:core:data DatabaseModule × 8 8 / 8

:core:viewmodel also declares its own 61 ViewmodelModule hints, which are not duplicated anywhere.

With 1.2.1, the same klibs declare no componentscan_* hint at all (:core:base has 3 definition_* hints, :core:data 5, :core:viewmodel none), and the framework links.

Expected

The hints of an included module are declared only in the klib of the Gradle module that owns that module, or the including module emits them under a signature of its own, so that the final link sees each signature once.

Possibly related

Activity

  1. aurimas-zarskis commented on Nov 9, 2026

    @aurimas-zarskis

    Same linker error here without includes. The duplicated hint is configuration_default, coming from @Configuration modules collected by @KoinApplication.

    Setup: koin-compiler-plugin 1.2.3 (1.2.1 links fine), koin/koin-annotations 4.2.2, Kotlin 2.4.21, iosSimulatorArm64 framework, compileSafety = false in every module.

    Each library module has a module like this:

    @Configuration
    @Module
    @ComponentScan("com.example.libraries.common")
    class CommonModule

    The app module (exported as the iOS framework) starts Koin with:

    @KoinApplication
    object KoinEntryPoint { /* startKoin<KoinEntryPoint> { ... } */ }

    All compileKotlinIosSimulatorArm64 tasks pass. linkDebugFrameworkIosSimulatorArm64 fails:

    e: IrSimpleFunctionSymbolImpl is already bound. Signature:                                                                          org.koin.plugin.hints/configuration_default|configuraibraries.common.di.CommonModule){}[0]
    

    klib dump-ir-signatures (Declared section) shows that the app klib re-declares configuration_default for every @Configuration module it aggregates (34 here). Each of those is alsolib:

    :libraries:common  → configuration_default(...CommonModule)
    :composeApp        → configuration_default(...CommonM
                         configuration_default(...CryptoModule)
                         configuration_default(...Network
                         ... (all 34 @Configuration modules)
    

    So this looks like the same relaying problem as above, triggered by @Configuration aggregation as well as includes.

  2. rlnt commented on Nov 12, 2026

    @rlnt

    Running into the same issue.

  3. MattSkala commented on Nov 13, 2026

    @MattSkala

    Same failure here. I traced it in the plugin source (1.2.3) and am posting what I found in case it shortens the fix.

    Our variant

    • koin-compiler-plugin 1.2.3 fails, 1.2.1 links. Koin 4.2.2, Kotlin 2.4.0, iosSimulatorArm64, static framework with export(...).
    • No includes is involved for the failing hint. :core has @Module @ComponentScan @Configuration class CoreModule, and the link fails on componentscan_…_CoreModule_factory(…).

    Cause

    1. KoinAnnotationProcessor.relayIncludedModuleHints and relayConfigurationHints (both present since 1.2.0) re-declare another Gradle module's hints inside the current module, under the owner's hint name and with the owner's parameter types. relayConfigurationHints relays configuration_default(Module) for every non-local @Configuration module it can see, then calls relayIncludedModuleHints for it, so that module's componentscan_* hints are re-declared too. Every dependent module does this, not only the one that starts Koin.
    2. Up to 1.2.1, IR-built hints were not serialized into KLIBs, so relays never left the compilation. 114de27 (fix: publish IR-built hints into KLIBs on Native/wasm/JS (#105, #106, #113) #129, the commonMain @Module hints dropped from klib when a platform source set also declares a @Module → false KOIN-D002 on Kotlin/Native #105 fix) parents every IR-built hint to the FIR anchor file in addHintFunctions, relays included.
    3. Dedupe is per compilation (relayedIncludedModuleFqNames, relayedConfigurationModuleFqNames). A comment in generateModuleScanHints says "Cross-Gradle-module duplicates are fine: separate klibs". That holds when one klib is written, but the Native linker binds the signatures of every klib it deserializes into one symbol table, so the second klib declaring the same hint fails with "already bound".

    Numbers (klib dump-ir-signatures, Declared section, 23 klibs containing Koin hints)

    • 1026 hint declarations, 301 distinct signatures, 139 declared in more than one klib: 121 componentscan_* and 18 configuration_default.
    • A single signature is declared in up to 16 klibs: the owner plus the modules that depend on it.
    • dsl_*, callsite, moduledef and annotationincludes hints are not duplicated in our build.

    Trigger: export()

    Same klibs, only the framework's export(...) lines changed:

    exports link
    none OK
    only a module with no Koin hints OK
    only :core (owns CoreModule) fails on CoreModule's hint

    The framework module itself relays CoreModule's hints, so exporting any klib that declares the same signature is enough.

    Notes for a fix

    No workaround found other than staying on 1.2.1 or dropping export().

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions