Search code examples
androidkotlindependencies

Error 'Unresolved reference: implementation' in build.gradle.kts file when adding Android dependencies


I'm encountering an issue in my Android project where I'm getting the error message "Unresolved reference: implementation" in the build.gradle.kts file when I attempt to add dependencies. I've included the relevant code snippets below :

plugins {
    id("com.android.application") version "8.2.0" apply false
    id("org.jetbrains.kotlin.android") version "1.8.10" apply false
}
dependencies {
    implementation("com.google.android.material:material:1.11.0")
}

I've already checked the syntax and structure, but I'm unable to resolve this issue. Any insights or suggestions on how to fix this would be greatly appreciated. Thank you!


Solution

  • If this is a module level build.gradle.kts then you should remove apply false.

    Plugins' versions are usually set in the top-level build.gradle.kts, but not applied to the whole project, hence apply false. Then you apply plugins in the module level build scripts.

    Top-level build.gradle.kts:

    plugins {
        id("com.android.application") version "8.2.0" apply false
        id("org.jetbrains.kotlin.android") version "1.8.10" apply false
    }
    

    Module level build.gradle.kts:

    plugins {
        id("com.android.application")
        id("org.jetbrains.kotlin.android")
    }