I am working on a multi Module Android project and I want to use the latest navigation library so I can take advantage of the Type Safe Navigation.
Just usual I added the library reference into the libs file and included that into the main module library
navigationVersion = "2.8.9"
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationVersion" }
dependencies {
implementation(libs.com.jakewharton.timber)
implementation(libs.androidx.security.cryto.ktx)
implementation(libs.bundles.compose)
implementation(libs.androidx.activity.kotlin)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.core.ktx)
implementation(libs.org.jetbrains.kotlinx.collections.immutable)
implementation(libs.com.google.android.gms.maps)
implementation(libs.androidx.navigation.compose) - HERE IS THE LIBRARY
....
and I am trying to use the typesafe navigation method but it keeps throwing me the issue it does not exist
@Serializable
data object Name
navHostController.navigate(Name)
Error code:
None of the following functions can be called with the arguments supplied.
navigate(Uri) defined in androidx. navigation. NavHostController
navigate(NavDeepLinkRequest) defined in androidx. navigation. NavHostController
navigate(NavDirections) defined in androidx. navigation. NavHostController
navigate(Int) defined in androidx. navigation. NavHostController
navigate(String, NavOptions? = ..., Navigator. Extras? = ...) defined in androidx. navigation. NavHostControlle
Then I noticed for some reason a 2.5.1
version is also presented in the project somehow besides the 2.8.9
version - but when I try to include the NavHostController
it uses it from the 2.5.1
version
There is no 2.5.1
version somehwere for this library reference on the libs.toml
so I have zero clue where they come from.
And while I was checking this I also realized there are a lot of libraries with multiple different versions.
Why so? How could I detect or remove where or how the older versions are included?
It looks like another library has a dependency on a lower version of the navigation. You can identify the problem by running and analyzing the file:
./gradlew :app:dependencies > dependencies.txt
But if you want to have only one version in the project, you can do so by using resolutionStrategy
:
configurations.all {
resolutionStrategy {
force 'androidx.navigation:navigation-compose:2.8.9'
}
}
More information about the ResolutionStrategy: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html