Hello I tried to run Kotlin file on Android Studio (version 4.1) and I got an error: Kotlin library {0} was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.
Even I got this error I'm able to run kotlin files but Ide don't gives me tips when I use kotlin functions and methods are marked by red colour. Kotlin version in gradle is 1.6.0, if I'm return to older version I can see tips about method names and red colour is not showed. Gradle build(app):
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.kotlin_udemy4"
minSdkVersion 26
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Gradle build:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.6.0"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
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
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Does anyon know how to resolve that issue ?
CodePudding user response:
Besides Kotlin version 1.6.21
...
That version of Android Studio appears rather outdated; eg. the current version "Chipmunk" uses:
com.android.tools.build:gradle:7.2.1
jcenter()
should be replaced withmavenCentral()
.- And also, use
JavaVersion.VERSION_11
.
CodePudding user response:
Next to isssue popup i selected "Details" link and there was information about expected version. Probably because I'm using older Android studio I got the problem. I updated Kotlin in gradle build to: 1.4.32 according to message.