I'm getting this error when building my iOS KMP ap...
# koin
m
I'm getting this error when building my iOS KMP app, it seems to be coming from Koin:
Copy code
> Task :umbrella:linkDebugFrameworkIosSimulatorArm64 FAILED
e: Compilation failed: IrPropertySymbolImpl is already bound. Signature: org.koin.ksp.generated/_defaultModule|{}_defaultModule[0]. Owner: PROPERTY name:_defaultModule visibility:public modality:FINAL [val]

 * Source files: 
 * Compiler version: 2.0.21
 * Output kind: FRAMEWORK

e: java.lang.IllegalStateException: IrPropertySymbolImpl is already bound. Signature: org.koin.ksp.generated/_defaultModule|{}_defaultModule[0]. Owner: PROPERTY name:_defaultModule visibility:public modality:FINAL [val]
        at org.jetbrains.kotlin.ir.symbols.impl.IrSymbolBase.bind(IrSymbolImpl.kt:67)
        at org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl.<init>(IrPropertyImpl.kt:63)
        at org.jetbrains.kotlin.ir.declarations.IrFactory.createProperty(IrFactory.kt:299)
        at org.jetbrains.kotlin.ir.declarations.IrFactory.createProperty$default(IrFactory.kt:282)
        at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrProperty$lambda$76$lambda$70(IrDeclarationDeserializer.kt:737)
        at org.jetbrains.kotlin.ir.util.SymbolTable.declareProperty(SymbolTable.kt:800)
        at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeIrProperty(IrDeclarationDeserializer.kt:735)
        at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration(IrDeclarationDeserializer.kt:800)
        at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeDeclaration$default(IrDeclarationDeserializer.kt:793)
        at org.jetbrains.kotlin.backend.common.serialization.IrFileDeserializer.deserializeDeclaration(IrFileDeserializer.kt:41)
        at org.jetbrains.kotlin.backend.common.serialization.FileDeserializationState.deserializeAllFileReachableTopLevel(IrFileDeserializer.kt:141)
        ...
I'm trying to figure out what have I changed in my last few commits that may have caused this, because this used to work just fine... But sharing in case anyone has any quick idea!
โœ… 1
I'm using
Copy code
koin = "4.0.0"
koinKsp = "1.4.0"
However I have tried with the newer beta versions and it does not resolve the issue
Android builds just fine
@arnaud.giuliani any ideas? We are currently blocked due to this ๐Ÿ˜ž
a
can you downgrade your kotlin version to 2.0.20 ?
and Koin annotations is not working on kotlin with 1.4.0. Go with 2.0.0-Beta1
m
Same issue ๐Ÿ˜ž I switched to
Copy code
koin = "4.0.0"
koinKsp = "2.0.0-Beta1"
kotlin = "2.0.20"
ksp = "2.0.20-1.0.25"
a
can you show what you try to generate? From annotated components, and the generated stuff
m
Is it worth showing you over a quick Huddle? It's a multi-module project so might be a bit hard to share the relevant parts over Slack
Oh, I think I solved it! Verifying again and I will share more details if that's the case
Solved ๐Ÿ™Œ This is what happened: I created a new project module (let's say
:core:datasource
) but I had not created a new explicit Koin module for the dependencies of that module. I have seen that it's not always required to do so, and only adding the annotations @Single or @Factory on those classes that I want to be injected does the trick (which it does on Android). However, for this one in particular, the iOS build was broken. @arnaud.giuliani should I always create specific Koin modules for all of the project modules? This is how the Module looks like:
Copy code
@Module
@ComponentScan("com.random.app.datasource")
class DataSourceModule
a
@ComponentScan can scan package over gradle modules, but not sure it's quite stable in KMP side
t
Jumping to the party a bit late ๐Ÿ™‚ I had the same issue and deactivated the Koin default modules
arg("KOIN_DEFAULT_MODULE","false")
I was not able to find out the purpose of the default modules as I am quite new to Koin, but didn't run into any issues after removing it. What I am trying to achieve is to create only one Koin Module that is annotated with
ComponentScan
. We are using KMP and have a bunch of gradle modules that are provided via one umbrella module for iOS. I put the "scan" module into the umbrella module and was able to scan all the sub projects successfully. I hope this is the right approach. I wanted to avoid creating a Koin Module for each Gradle Module.
Copy code
/**
 * Helper function to scan all annotated modules and provide them via Koin
 * TODO check if this is the better approach or if each module should expose it's own module
 */
fun scannedModules() = listOf(GlobalComponentScanModule().module)

@Module
@ComponentScan("com.company.shared")
public class GlobalComponentScanModule
@arnaud.giuliani is this approach a way to go without creating a module for each gradle module or does it bloat up at some point?
a
default module is generated if you don't have a proper module affected to your definitions. We also need a the defaults file to help export definitions, to be scanned outside of your module
t
Now I am confused ๐Ÿ™‚. We disabled the default modules. Does that mean it should not work for us?
a
disabling the default module will warn if you have any definition outside of any module, else it would put those definitions inside the default module
you can freely disable it, apart if you were using it actively before
๐Ÿ‘ 1
198 Views