androidandroid-studiogradlekotlin

Android Stuido: How to change Kotlin version that is used for building with Gradle


Android Studio is giving a warning saying: "Kotlin version that is used for building with Gradle (1.3.10) differs from the one bundled into the IDE plugin (1.3.41)".

How can i change the Kotlin version used by Gradle?

I have installed the latest Android Studio version(3.4.2) with the latest Kotlin plugin(1.3.41-release-Studio3.4-1)

I have also tried to change the kotlin version in the build.gradle file, but its saved in a variable "kotlin_version$"

dependencies {
    // ....
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

Solution

  • I have also tried to change the kotlin version in the build.gradle file, but its saved in a variable "kotlin_version$"

    That variable is defined earlier in the file. Here is a typical top-level build.gradle file:

    buildscript {
        ext.kotlin_version = '1.3.41'
        repositories {
            google()
            jcenter()
    
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
    
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    The second line of that file is:

        ext.kotlin_version = '1.3.41'
    

    That is where kotlin_version is defined, that is then used in "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version".

    So, change ext.kotlin_version to be the value that you want.