1

I'm working on a KMP project targeting android, ios and desktop and I'm using koin as DI, all works fine in Android and desktop(windows and macOS) but the build for iOS fails.

some of my dependencies versions:

[versions]
compose = "1.6.5"
compose-plugin = "1.6.2"
kotlin = "1.9.23"
koin = "3.6.0-alpha3"
koin-compose = "3.6.0-wasm-alpha2"

[libraries]
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin-compose" }

[plugins]
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }

my build.gradle

commonMain.dependencies {
    implementation(compose.runtime)
    implementation(compose.foundation)
    implementation(compose.material)
    implementation(compose.ui)
    implementation(compose.components.resources)
    implementation(compose.components.uiToolingPreview)

    implementation(libs.koin.core)
    implementation(libs.koin.compose)

    implementation(libs.ktor.client.core)
    implementation(libs.kotlinx.coroutines.core)
    implementation(libs.ktor.client.content.negotiation)
    implementation(libs.ktor.client.serialization.kotlinx.json)

    implementation("org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha01")

    implementation(libs.coil.compose)
}

my App composable in commonMain

@Composable
@Preview
fun App() {
    val navController = rememberNavController()
    KoinApplication(application = {
        modules(appModule())
    }) {
        Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
            BaseNavHost(
                navController = navController,
            )
        }
    }
}

and a example of a screen(Note: the HomeViewModel is not a real one, its just a regular class)

@Composable
fun HomeScreen(
    modifier: Modifier = Modifier,
    homeViewModel: HomeViewModel = koinInject()
) {
//some stuffs
}

running on android and desktop works fine but for iOS fail with this error:

Task :composeApp:compileKotlinIosSimulatorArm64 FAILED
error: Could not find "org.jetbrains.compose.annotation-internal:annotation"

any idea?

1 Answer 1

0

I got the same error today, and after doing some research, I solved it by doing these:

  • Changing io.insert-koin:koin-compose version to 1.2.0-Beta4
  • implementing co.touchlab:stately-concurrent-collections:2.0.6 as common dependency as it seems like Koin is pulling an outdated version or something.

libs.versions.toml file:

[versions]
...
koin = "3.6.0-wasm-alpha2"
koin-compose = "1.2.0-Beta4"

[libraries]
...
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin-compose" }

build.gradle.kts file:

commonMain.dependencies {
       ...
       implementation("co.touchlab:stately-concurrent-collections:2.0.6")
       implementation(libs.koin.core)
       implementation(libs.koin.compose)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.