Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin compile "ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher." but no kotlin_version in build.gradle?

I tried cloning and building this project, https://github.com/mitrejcevski/ui-testing, but upon opening it in Android Studio, I get the following build error:

ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
The following dependencies do not satisfy the required version:
root project 'ui-testing' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21
Affected Modules: app

However, when I click the 'app' hyperlink I am led to the module-level build.gradle file, which reads

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

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "nl.jovmit"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        mock {
            flavorDimensions "default"
        }
        prod {
            flavorDimensions "default"
        }
    }

    android.variantFilter { variant ->
        if (variant.buildType.name == 'release' && variant.getFlavors().get(0).name == 'mock') {
            variant.setIgnore(true)
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    testImplementation 'junit:junit:4.12'
}

Unlike the accepted answer of ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher, I don't see any ext.kotlin_version anywhere in the Gradle file.

I do see this warning, though, that kotlin-stdlib-jre7 is deprecated:

enter image description here

However, I tried changing this but still get the same error. I've also tried adding the line

implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'

to dependencies (as seen in the screenshot above), but that also didn't prevent the error.

Any idea how to fix this? I suspect that the outdated Kotlin version is a 'sub-dependency' of one of the dependencies here, but haven't been able to figure out which one.

like image 277
Kurt Peek Avatar asked Feb 25 '19 01:02

Kurt Peek


People also ask

How do I update my Kotlin gradle plugin in flutter?

All you need to do is to open the <your project>/android/build. gradle file then update ext. kotlin_version to a newer version: At the time of writing, the latest version is 1.6.

What is kapt in gradle?

1. Kapt is the Kotlin Annotation Processing Tool, and it's in pretty good shape these days. If you want to be able to reference generated code from Kotlin, you need to use kapt. To do that, simply include the plugin in your build.gradle file with the line : apply plugin: 'kotlin-kapt' 2.


Video Answer


1 Answers

Define your ext.kotlin_version

Your project level build.gradle should look like this.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
like image 159
Debanjan Avatar answered Oct 09 '22 03:10

Debanjan