[null,null,["最后更新时间 (UTC):2025-08-31。"],[],[],null,["# Kotlin version compatibility and migration\n\nThis page provides information about Kotlin version compatibility for the\nNavigation SDK, as well as guidance for migrating to a newer version.\n\nNavigation SDK Kotlin version requirements\n------------------------------------------\n\nThe following table outlines the Kotlin version requirements and the recommended\nAGP and Gradle versions for recent versions of the Navigation SDK.\n\n| Navigation SDK version | Kotlin version (required) | Android Gradle Plugin (AGP) and Gradle versions (recommended) |\n|------------------------|---------------------------|---------------------------------------------------------------------------------------------------------------------|\n| 6.2+ | 2.1 | - AGP 8.7.3 - Gradle 8.10.2 |\n| 6.0 - 6.2 | 2.0 | - AGP 8.3.0 - Gradle 8.4 |\n| 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). |\n\n| **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.\n\nKotlin version compatibility\n----------------------------\n\nKotlin 2.1 supports backwards compatibility with Kotlin 2.0. This means that if\nyou are already using Kotlin 2.0 with the Navigation SDK, you should be able to\nupgrade to Kotlin 2.1 without having to resolve all of the breaking changes.\nHowever, this only applies to [stable language\nfeatures](https://kotlinlang.org/docs/components-stability.html#stability-levels-explained).\nIf you are using alpha, beta or experimental features in the Kotlin language,\nthen you may have to make additional changes when upgrading.\n\n### Easing the transition: Kotlin compatibility flags\n\nKotlin supplies two flags to help with limiting breaking changes:\n\u003chttps://kotlinlang.org/docs/compatibility-modes.html\u003e\n\n#### language-version X.Y\n\nThis flag reverts breaking changes to the behavior of a previous Kotlin version.\nFor example, if you are using Kotlin 2.0, you could specify `[ -\nlanguage-version 2.0]` and the new breaking changes would no longer take effect: \n\n android {\n kotlinOptions {\n languageVersion = '2.0'\n }\n }\n\n#### api-version X.Y\n\nThis flag throws a Gradle build error when an API from a Kotlin version newer\nthan the `apiVersion` is used. \n\n android {\n kotlinOptions {\n apiVersion = '2.0'\n }\n }\n\n### A more targeted approach\n\nIn addition to using Kotlin compatibility flags, we recommend reviewing the\nKotlin release notes and choosing the behaviors that you would like to retain\nfrom the version that you are upgrading from. Kotlin provides a list of breaking\nchanges and the flags that can be set to retain the original behavior in its\ncompatibility guides for each version:\n\n- [1.9 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-19.html)\n- [2.0 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-20.html)\n- [2.1 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-21.html)\n\nFuture Kotlin upgrades\n----------------------\n\nKotlin releases a new version (i.e. language release) [every 6\nmonths](https://kotlinlang.org/docs/releases.html#kotlin-release-compatibility)\nand Google typically incorporates the latest version as the default in our\nproducts 1-2 months after that. Previous Kotlin versions have included breaking\nchanges that have required Navigation SDK customers to upgrade to a newer\nversion. Because of this, we recommend that you plan for a Kotlin upgrade every\n6 months when adopting the latest Navigation SDK version."]]