Reputation: 331
Quick Summary:
Build Script isn't working with 'Compose for Desktop'. I have been able to use compose quite extensively (in terms of composables), and now unable to use the navigation part.
I am getting the error:
> Configure project :
Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.
> Task :prepareKotlinBuildScriptModel UP-TO-DATE
Could not resolve: androidx.navigation:navigation-compose:2.5.2
Could not resolve: androidx.navigation:navigation-compose:2.5.2
BUILD SUCCESSFUL in 683ms
with the below build.gradle.kts
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
group = "com.example"
version = "1.0-SNAPSHOT"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
withJava()
}
sourceSets {
val jvmMain by getting {
dependencies {
implementation(compose.desktop.currentOs)
// val navVersion = "2.7.3"
val navVersion = "2.5.2"
// Jetpack Compose Integration
implementation("androidx.navigation:navigation-compose:$navVersion")
}
}
val jvmTest by getting
}
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "NavTest"
packageVersion = "1.0.0"
}
}
}
Original Post:
There are still some problems on my end in order to get the navigation working.
I would like to be able to navigate from one screen/view/composable to another with some data, such as IDs.
I have been able to use https://github.com/itheamc/navigation-for-compose-for-desktop to test that navigation can work properly. In this case it doesn't allow for the full set of functionality that is expected out of current Android compose. I would like to be able to use routes to pass data, etc.
What is the standard way to complete navigation with Compose for Desktop? It has been difficult to follow the code labs and other documentation, stating use rememberNavController(), etc. when they are not available from the native libraries. There always seems to be a missing step in getting the navController to be setup and work. Also following along with the above linked example, everything has been built custom and not been able to use the, at least for me, standard compose functions, such as rememberNavController. These functions have been adjusted for a custom purpose rather than it be used as an example case.
I have implemented dependencies but they don't seem to work to work properly in my project either. 'androidx.compose-navigation:2.7.3' (I used the correct syntax, this is simplified)
I have tried to use arguments. These are not available in the above example, and I haven't been able to build a project suitable to use the navigation library properly (or to at least use the imports that I can see from other examples online).
If possible, could an example be created:
Anything that is able to better represent the current state and possibilities of Compose Navigation for Desktop.
I expect that my main problem is directly the build script. But I am still unsure if there is a direct crossover from Android or not for the desktop functions of compose, at least in the setup.
Thank you for any help.
Upvotes: 0
Views: 798
Reputation: 88082
androidx.navigation is Android specific library, you can't use it with Compose Desktop.
There are many off-the-shelf KMP navigation solutions, a list can be found here.
I'm not sure if there is something close to Compose Navigation, as many people don't like the limitations associated with passing arguments.
Personally, I use Decompose - it can be a bit tricky to get started - good documentation will help you with that, but once I'm used to it, very happy with it.
Upvotes: 2