Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency of navigation-compose failed to sync on Compose Multiplatform project

I was building a desktop application using Compose Multiplatform and I need a navigation. I followed the guides and added a dependency of androidx.navigation:navigation-compose with version 2.7.7.

// /gradle/libs.versions.toml
[versions]
compose = "1.6.2"
compose-plugin = "1.6.0"
junit = "4.13.2"
kotlin = "1.9.22"
kotlin-serialization-json = "1.6.3"
ktor = "2.3.10"
coroutines = "1.8.0"
nav = "2.6.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization-json" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
compose-nav = { module = "androidx.navigation:navigation-compose", version.ref = "nav" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-engine = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }

[plugins]
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
// /composeApp/build.gradle.kts
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.kotlinSerialization)

    alias(libs.plugins.jetbrainsCompose)
}

kotlin {
    jvm("desktop")
    
    sourceSets {
        val desktopMain by getting
        
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
//            implementation(kotlin.serialization.json)
            implementation(libs.ktor.client.core)
            implementation(libs.ktor.client.engine)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)
            implementation(libs.kotlinx.coroutines.core)
            implementation(libs.compose.nav)
        }
        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
        }
    }
}


compose.desktop {
    application {
        mainClass = "MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "com.myproject"
            packageVersion = "1.0.0"
        }
    }
}

But when I sync it with Android Studio, I got errors as below.

:composeApp:commonMain: Could not resolve androidx.compose.animation:animation:1.5.1.
Required by:
    project :composeApp > androidx.navigation:navigation-compose:2.7.7

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
:composeApp:commonMain: Could not resolve androidx.compose.runtime:runtime:1.5.1.
Required by:
    project :composeApp > androidx.navigation:navigation-compose:2.7.7

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

I tried using an old version of 2.6.0, it passed sync but I couldn't import it in my program and use rememberNavController and NavHost as the guides describes.

Can anyone help me?

like image 828
W Walliet Avatar asked Oct 23 '25 15:10

W Walliet


1 Answers

This is because you have different dependencies. please see the dependency provided by Kotlin officials. reference link

org.jetbrains.androidx.navigation:navigation-compose: // latest version
like image 64
Mohammad Hanif Shaikh Avatar answered Oct 26 '25 06:10

Mohammad Hanif Shaikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!