This page provides information about Kotlin version compatibility for the Navigation SDK, as well as guidance for migrating to a newer version.
Navigation SDK Kotlin version requirements
The following table outlines the Kotlin version requirements and the recommended AGP and Gradle versions for recent versions of the Navigation SDK.
Navigation SDK version | Kotlin version (required) | Android Gradle Plugin (AGP) and Gradle versions (recommended) |
---|---|---|
6.2+ | 2.1 |
|
6.0 - 6.2 | 2.0 |
|
5.1 - 5.99.1 | 1.9 | We recommend using AGP 7.3+, which has a workaround for JDK-8272564. |
Kotlin version compatibility
Kotlin 2.1 supports backwards compatibility with Kotlin 2.0. This means that if you are already using Kotlin 2.0 with the Navigation SDK, you should be able to upgrade to Kotlin 2.1 without having to resolve all of the breaking changes. However, this only applies to stable language features. If you are using alpha, beta or experimental features in the Kotlin language, then you may have to make additional changes when upgrading.
Easing the transition: Kotlin compatibility flags
Kotlin supplies two flags to help with limiting breaking changes: https://kotlinlang.org/docs/compatibility-modes.html
language-version X.Y
This flag reverts breaking changes to the behavior of a previous Kotlin version.
For example, if you are using Kotlin 2.0, you could specify [ -
language-version 2.0]
and the new breaking changes would no longer take effect:
android {
kotlinOptions {
languageVersion = '2.0'
}
}
api-version X.Y
This flag throws a Gradle build error when an API from a Kotlin version newer
than the apiVersion
is used.
android {
kotlinOptions {
apiVersion = '2.0'
}
}
A more targeted approach
In addition to using Kotlin compatibility flags, we recommend reviewing the Kotlin release notes and choosing the behaviors that you would like to retain from the version that you are upgrading from. Kotlin provides a list of breaking changes and the flags that can be set to retain the original behavior in its compatibility guides for each version:
Future Kotlin upgrades
Kotlin releases a new version (i.e. language release) every 6 months and Google typically incorporates the latest version as the default in our products 1-2 months after that. Previous Kotlin versions have included breaking changes that have required Navigation SDK customers to upgrade to a newer version. Because of this, we recommend that you plan for a Kotlin upgrade every 6 months when adopting the latest Navigation SDK version.