Reputation: 107
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 ?
Upvotes: 2
Views: 12580
Reputation: 305
This problem is due to the gradle version of your project.
You can try the following steps to resolve this error, by upgrading the version of your android studio in the following steps.
Go to the buil.gradle (Project level) and update the version of your build tools and plugin
dependencies { //Old version classpath "com.android.tools.build:gradle:7.0.0-rc01" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
// change to the new one
classpath "com.android.tools.build:gradle:7.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
Now navigate to the gradle-wrapper.properties and update your gradel version
// old version distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
// change to the new version distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-bin.zip
//old version
compileSdk 31
//new version compileSdk 34
Please sometime If you are not sure with the new version simply scroll the mouse on the previous version and the new version will be highlighted which you can update accordingly
Upvotes: 0
Reputation: 29
I have similar problem. To solve this, I do the following things:
I try to Rebuild the project, then this error log appear: The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.appcompat:appcompat-resources:1.5.0. AAR metadata file: C:\Users..........
Lower androidx.appcompat:appcompat version to 1.4.0, and then sync gradle. That's it.
Maybe you can try this way.
Upvotes: 2
Reputation: 76799
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 with mavenCentral()
.JavaVersion.VERSION_11
.Upvotes: 1
Reputation: 107
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.
Upvotes: -1