Android Studio : Could not get unknown property 'kotlin_version'

Viewed 12988

After git cloning from here,

I first faced with this error:

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\...\voicegym\app\build.gradle' line: 3

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not initialize class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt

following this advice, i added these to build.gradle (Project: voicegym)

buildscript {
    ext.kotlinVersion = '1.3.72' // previously  '1.2.60'
    ext.springBootVersion = '2.0.4.RELEASE'
    ext.anko_version='0.10.4'
    repositories {
        ...
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Now, i have this error

Build file 'C:\...\voicegym\build.gradle' line: 5

A problem occurred evaluating root project 'voicegym'.
> Could not get unknown property 'kotlin_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
4 Answers

after experimenting, it should be ext.kotlin_version=... instead of ext.kotlinVersion =...

buildscript {
    ext.kotlin_version= '1.3.72' // previously  '1.2.60'
    ext.springBootVersion = '2.0.4.RELEASE'
    ext.anko_version='0.10.4'
    repositories {
        ...
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

All you need to do to fix this error is to add the following line in ext component inside "Android/build.gradle(Project:projectName) file:

kotlin_version = '1.5.31'

The ext component will look like:

ext {
activityVersion = '1.4.0'
appCompatVersion = '1.4.0'
constraintLayoutVersion = '2.1.2'
coreTestingVersion = '2.1.0'
coroutines = '1.5.2'
lifecycleVersion = '2.4.0'
materialVersion = '1.4.0'
roomVersion = '2.3.0'
// testing
junitVersion = '4.13.2'
espressoVersion = '3.4.0'
androidxJunitVersion = '1.1.3'
 //Add the kotlin version here:
kotlin_version = '1.5.31'

}

Inside android/build.gradle file place below code:

buildscript {
ext.kotlin_version = '1.5.31'
repositories {
    google()
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:7.0.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 }
}

Inside app/build.gradle file place below code:

dependencies {
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

just add ext.kotlin_version= "1.3.72" like this

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {

the error will definetly resolved

Related