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) |
|---|---|---|
| 8.0+ | 2.3.0 | - AGP 9.0.1 - Gradle 9.1.0 **Important:** For Navigation SDK 8.0 and higher, AGP 9.0.1 is a minimum requirement rather than a recommendation. The SDK declares `minAndroidGradlePluginVersion=9.0.1`, and builds using an earlier version of AGP fail. |
| 7.7 - 7.9 | 2.3.0 | - AGP 8.13.2 - Gradle 8.13 |
| 7.3 - 7.6 | 2.2.10 | - AGP 8.10.0 - Gradle 8.11.1 |
| 6.3 - 7.2 | 2.1 | - AGP 8.7.3 - Gradle 8.10.2 |
| 6.0 - 6.2 | 2.0 | - AGP 8.3.0 - Gradle 8.4 |
| 5.1 - 5.99.1 | 1.9 | We recommend using AGP 7.3+, which has a workaround for [JDK-8272564](https://bugs.openjdk.org/browse/JDK-8272564). |

> [!NOTE]
> **Note:** The recommended AGP versions listed above account for the use of R8/D8, which is included with AGP. If you are not using R8/D8, see the Kotlin [requirements for the minimum and maximum versions](https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin) for Gradle and AGP.

## Kotlin version compatibility

Kotlin 2.3 supports backwards compatibility with Kotlin 2.2. This means that if
you are already using Kotlin 2.2 with the Navigation SDK, you should be able to
upgrade to Kotlin 2.3 without having to resolve all of the breaking changes.
However, this only applies to [stable language
features](https://kotlinlang.org/docs/components-stability.html#stability-levels-explained).
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.2, you could specify `[ -
language-version 2.2]` and the new breaking changes would no longer take effect:

    android {
       kotlinOptions {
           languageVersion = '2.2'
       }
    }

#### 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.2'
       }
    }

### 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:

- [2.0 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-20.html)
- [2.1 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-21.html)
- [2.2 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-22.html)
- [2.3 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-23.html)

## Future Kotlin upgrades

Kotlin releases a new version (i.e. language release) [every 6
months](https://kotlinlang.org/docs/releases.html#kotlin-release-compatibility)
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.