Skip to content

Generated ViewModel declaration in module differs between Android and iOS in Compose Multiplatform app #283

@krzdabrowski

Description

@krzdabrowski

Describe the bug
I have a fully KMP & CMP app where my abstract class BaseViewModel reside in :core module, in commonMain, and multiple feature modules are implementing it, for example class LoginViewModel(...) : BaseViewModel() (in commonMains too). All ViewModels are wrapped with @KoinViewModel.

I noticed that in build/generated classes, the modules' code differ between platforms, causing serious issue - I'm not able to build the iOS app. See details below.

To Reproduce

In ksp/android, my example LoginModule looks like this:

public val package_LoginModule : Module get() = module {
	viewModel() { _ -> package.LoginViewModel(...) } 
}
public val package.LoginModule.module : org.koin.core.module.Module get() = package_LoginModule

However, in ksp/iosArm64, LoginViewModel is explicitly binded with its parent:

public val package_LoginModule : Module get() = module {
	viewModel() { _ -> package.LoginViewModel(...) } bind(otherpackage.BaseViewModel::class)
}
public val package.LoginModule.module : org.koin.core.module.Module get() = package_LoginModule

This causes a big issue in KoinMeta generated file for iOS because such entry is added:

public fun _KSP_OtherPackageBaseViewModel() : Unit = Unit

As multiple ViewModels are implementing BaseViewModel in different Gradle feature modules, this entry exists in many generated files, with the same name for BaseViewModel.

In result, running :shared-ios-module:linkDebugFrameworkIosArm64 causes a duplication failure:

e: Compilation failed: IrSimpleFunctionSymbolImpl is already bound. Signature: org.koin.ksp.generated/_KSP_OtherPackageBaseViewModel|_KSP_OtherPackageBaseViewModel(){}[0]. Owner: FUN name:_KSP_OtherPackageBaseViewModel visibility:public modality:FINAL <> () returnType:<unbound IrClassSymbolImpl>

And finally, I'm not able to build the iOS version of the app 😞

Expected behavior
Generated modules (for ViewModels) should be the same no matter the target platform; in this case I believe there should be no binding for BaseViewModel like Android does - because Android app compiles and works fine.

Koin project used and used version:

  • Koin 4.1.0-Beta8, can't get higher due to this bug
  • Koin Annotations 2.0.0 or 2.0.1-RC1.
  • other dependencies are the latest stable possible from JetBrains, like ViewModel KMP/CMP dependency

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions