Simplifies navigation between UI destinations via a consistent API, offers type-safe arguments (Safe Args), Compose and fragment integrations, feature-module support, and testing utilities.
Navigation is a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, Activities, or other components.
To add a dependency on Navigation, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
Add the dependencies for the artifacts you need in the build.gradle file for your app or module:
plugins {
// Kotlin serialization plugin for type safe routes and navigation arguments
kotlin("plugin.serialization") version "2.0.21"
}
dependencies {
val nav_version = "2.9.6"
// Jetpack Compose integration
implementation("androidx.navigation:navigation-compose:$nav_version")
// Views/Fragments integration
implementation("androidx.navigation:navigation-fragment:$nav_version")
implementation("androidx.navigation:navigation-ui:$nav_version")
// Feature module support for Fragments
implementation("androidx.navigation:navigation-dynamic-features-fragment:$nav_version")
// Testing Navigation
androidTestImplementation("androidx.navigation:navigation-testing:$nav_version")
// JSON serialization library, works with the Kotlin serialization plugin
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}
plugins {
// Kotlin serialization plugin for type safe routes and navigation arguments
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.21'
}
dependencies {
def nav_version = "2.9.6"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:$nav_version"
// Views/Fragments Integration
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Feature module support for Fragments
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// JSON serialization library, works with the Kotlin serialization plugin.
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3"
}
To add Safe Args to your project, include the following classpath in your top level build.gradle file:
buildscript {
repositories {
google()
}
dependencies {
val nav_version = "2.9.6"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.9.6"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
You must also apply one of two available plugins.
To generate Java language code suitable for Java or mixed Java and Kotlin modules, add this line to your app or module's build.gradle file:
plugins {
id("androidx.navigation.safeargs")
}
plugins {
id 'androidx.navigation.safeargs'
}
Alternatively, to generate Kotlin code suitable for Kotlin-only modules, add:
plugins {
id("androidx.navigation.safeargs.kotlin")
}
plugins {
id 'androidx.navigation.safeargs.kotlin'
}
You must have android.useAndroidX=true in your gradle.properties file as per Migrating to AndroidX.
For information on using Kotlin extensions, see the ktx documentation.
For more information about dependencies, see Add Build Dependencies.
Navigation is a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, Activities, or other components.
To add a dependency on Navigation, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.
Add the dependencies for the artifacts you need in the build.gradle file for your app or module:
plugins {
// Kotlin serialization plugin for type safe routes and navigation arguments
kotlin("plugin.serialization") version "2.0.21"
}
dependencies {
val nav_version = "2.9.6"
// Jetpack Compose integration
implementation("androidx.navigation:navigation-compose:$nav_version")
// Views/Fragments integration
implementation("androidx.navigation:navigation-fragment:$nav_version")
implementation("androidx.navigation:navigation-ui:$nav_version")
// Feature module support for Fragments
implementation("androidx.navigation:navigation-dynamic-features-fragment:$nav_version")
// Testing Navigation
androidTestImplementation("androidx.navigation:navigation-testing:$nav_version")
// JSON serialization library, works with the Kotlin serialization plugin
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}
plugins {
// Kotlin serialization plugin for type safe routes and navigation arguments
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.21'
}
dependencies {
def nav_version = "2.9.6"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:$nav_version"
// Views/Fragments Integration
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Feature module support for Fragments
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// JSON serialization library, works with the Kotlin serialization plugin.
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3"
}
To add Safe Args to your project, include the following classpath in your top level build.gradle file:
buildscript {
repositories {
google()
}
dependencies {
val nav_version = "2.9.6"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.9.6"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
You must also apply one of two available plugins.
To generate Java language code suitable for Java or mixed Java and Kotlin modules, add this line to your app or module's build.gradle file:
plugins {
id("androidx.navigation.safeargs")
}
plugins {
id 'androidx.navigation.safeargs'
}
Alternatively, to generate Kotlin code suitable for Kotlin-only modules, add:
plugins {
id("androidx.navigation.safeargs.kotlin")
}
plugins {
id 'androidx.navigation.safeargs.kotlin'
}
You must have android.useAndroidX=true in your gradle.properties file as per Migrating to AndroidX.
For information on using Kotlin extensions, see the ktx documentation.
For more information about dependencies, see Add Build Dependencies.