# Android Studio: How to Update Kotlin, Gradle, and AGP

> Update the Kotlin, Android Gradle plugin, Gradle wrapper, and JDK versions together in build.gradle files to avoid plugin and compiler incompatibility errors

**URL:** https://sentry.io/answers/how-to-update-kotlin-in-android-studio/

---

## The Problem

You can avoid unexpected issues by keeping the Kotlin versions in your project updated, especially when updating Gradle versions.

Each Kotlin version has a minimum and maximum supported Gradle version and using incompatible versions may cause errors such as:

```
BUILD FAILED in 8s
[!] Your project requires a newer version of the Kotlin Gradle plugin.
    Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update project/android/build.gradle:
    ext.kotlin_version = '<latest-version>'
Exception: Gradle task assembleDebug failed with exit code 1
```

## The Solution

When updating Kotlin to the latest version, update the Android Gradle plugin (AGP), Gradle, and the Java Development Kit (JDK) to avoid incompatibility issues.

First, open the project-level `build.gradle` file located in the root of your project and update the `plugins` block. The example below will update Kotlin to version 2.4.0:

```groovy
plugins {
    id 'com.android.application' version '9.4.0' apply false
    id 'com.android.library' version '9.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '2.4.0' apply false
}
```

The lines containing `com.android.application` and `com.android.library` update the Android Gradle plugin.

Next, update Gradle by navigating to the `gradle/gradle-wrapper.properties` file and changing the version number in the `distributionUrl`. Here we're using Gradle version 9.7.1:

```
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
```

To update the JDK to use Java 17, open the `app/build.gradle` file and update the following lines:

```groovy
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = '17'
}
```

Finally, update the Gradle JDK in Android Studio **Settings**. Go to **File** (or **Android Studio** on macOS) > **Settings** > **Build, Execution, Deployment** > **Build Tools** > **Gradle** and change the "Gradle JDK" field to "17".

![Gradle JDK Settings](gradle-jdk-settings.png)

For more information about the Android build system, visit https://developer.android.com/build.

---

*Source: [sentry.io/answers/how-to-update-kotlin-in-android-studio/](https://sentry.io/answers/how-to-update-kotlin-in-android-studio/)*
