Fix Android build error: Plugin with id 'kotlin-android' not found.

When building an Android application that uses Kotlin language, you might encounter an error that says plugin kotlin-android not found.

The error in the build console appears as follows:

> Plugin with id 'kotlin-android' not found.

* Try:
Run with --info or --debug option to get more log output. 
Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: 
A problem occurred evaluating project ':app'.
... 130 more

This error happens when Gradle tries to apply the Kotlin language plugin for your Android app build, but can’t find the dependency classpath.

To fix the error, you need to add kotlin-gradle-plugin to your build.gradle file as shown below:

buildscript {
    ext.kotlin_version = '1.6.21'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The latest version of the Kotlin plugin can be found on Jetbrains Kotlin plugin page.

You can change the plugin version used by changing the ext.kotlin_version property above.

Please note that the Kotlin plugin needs to be added to the root build.gradle file and not the app/build.gradle file.

The app/build.gradle file is where the plugin is applied as shown below:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    // ...
}

The apply plugin: 'kotlin-android' line will cause the error when the classpath to Kotlin plugin is not added to the root build.gradle file.

In the latest Android Studio version, the root build.gradle file content no longer uses the classpath dependencies.

The root or top-level dependencies are listed as follows:

plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The latest Android Studio lists the dependencies using Gradle plugins DSL as shown on Kotlin plugins for Gradle documentation.

Make sure the highlighted line above is present in your build.gradle file to resolve the issue.

Now you’ve learned how to fix the Android build error: Plugin with id ‘kotlin-android’ not found.

Good work! 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.