## Migrate to Kotlin 2.0

If you are using the Consumer SDK for Android 3.0+ you must upgrade to Kotlin
2.0. This page provides guidance to ease the transition to the new Kotlin
version.

> [!NOTE]
> **Note:** For information on upgrading to Kotlin 1.9, which was required for the Consumer SDK 5.0+ see the [Kotlin 1.9 upgrade
> guide](https://developers.google.com/maps/documentation/transportation-logistics/on-demand-rides-deliveries-solution/trip-order-progress/migrations/android_consumer_sdk_v2.0_migration#kotlin_16_to_19_migration).

### Gradle and AGP compatibility

Kotlin 2.0 has [requirements for the minimum and maximum
versions](https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin)
for your Gradle and Android Gradle Plugin (AGP) version. Ensure that your
project meets these requirements for Kotlin 2.0.

#### AGP minimum version for the Consumer SDK 3.0+

Consumer SDK 3.0 requires using AGP 7.3+.

##### Full R8 mode

Consumer SDK v3 and below does not support Full R8 mode. You must explicitly
disable Full R8 mode if your application targets AGP 8.0+.

```groovy
# settings.gradle
android.enableR8.fullMode=false
```

### Kotlin version compatibility

Kotlin supports backwards compatibility with [three previous language
versions](https://kotlinlang.org/docs/kotlin-evolution-principles.html#compatibility-options).
This means that if you are already using Kotlin 1.7+ with the Consumer SDK, you
should be able to upgrade to Kotlin 2.0 without having to resolve all of the
breaking changes. However, [Kotlin compatibility 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.

#### Kotlin compatibility flags

As noted in the previous section, Kotlin supports up to 3 previous versions of
the language when upgrading. 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 1.7, you could specify `[ -
language-version 1.7]` and the new breaking changes would no longer take effect:

```kotlin
android {
   kotlinOptions {
       languageVersion = '1.7'
   }
}
```

##### api-version X.Y

This flag prevents new APIs from being used before dependent downstream code is
ready to incorporate Kotlin 2.0.

```kotlin
android {
   kotlinOptions {
       apiVersion = '1.7'
   }
}
```

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

- [1.8 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-18.html)
- [1.9 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-19.html)
- [2.0 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-20.html)