您好,我尝试在Android Studio(版本4.1)上运行Kotlin文件,但遇到错误:Kotlin库{0}是使用较新的Kotlin编译器编译的,无法读取。请更新Kotlin插件。
即使我得到了这个错误,我也可以运行Kotlin文件,但IDE在我使用Kotlin函数和方法时不给我提示,方法用红色标记。Gradle中的Kotlin版本是1.6.0,如果我返回到旧版本,我可以看到关于方法名称的提示,红色不显示。Gradle构建(应用程序):
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构建:
// 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
}
型
有人知道如何解决这个问题吗?
4条答案
按热度按时间baubqpgj1#
我也有类似的问题。为了解决这个问题,我做了以下事情:
1.我尝试重新构建项目,然后出现此错误日志:在依赖项的AAR元数据(META-INF/com/android/build/gradle/aar-metadata.properties)中指定的mininstanceSdk(32)大于此模块的compileSdkVersion(android-31)。依赖项:androidx.appcompat:appcompat-resources:1.5.0. AAR元数据文件:C:\Users...
1.将androidx.appcompat:appcompat版本降低到1.4.0,然后同步gradle。就是这样。
也许你可以试试这种方式。
disho6za2#
除了Kotlin版本
1.6.21
.该版本的Android Studio似乎相当过时;例如.当前版本“花栗鼠”使用:
com.android.tools.build:gradle:7.2.1
个jcenter()
应替换为mavenCentral()
。JavaVersion.VERSION_11
。uqcuzwp83#
此问题是由于项目的gradle版本造成的。
您可以尝试以下步骤来解决此错误,通过在以下步骤中升级您的android studio版本.
1.转到buil.gradle(项目级)并更新构建工具和插件的版本
dependencies { //旧版本classpath“com.android.tools.build:gradle:7.0.0-rc 01”classpath“org.jetbrains.Kotlin:kotlin-gradle-plugin:1.5.21”
字符串
}
1.现在导航到gradle-wrapper.properties并更新您的gradel版本
//旧版本distributionUrl=https:services.gradle.org/distributions/gradle-7.0.2-bin.zip
//更改为新版本distributionUrl=https:services.gradle.org/distributions/gradle-7.3.3-bin.zip
1.最后在build.gradle中修改编译SDK版本(模块级)
//旧版本
compileSdk 31
//新版本compileSdk 34
如果您不确定新版本,请在以前的版本上滚动鼠标,新版本将突出显示,您可以相应地更新
vom3gejh4#
在问题弹出窗口旁边,我选择了“详细信息”链接,并有关于预期版本的信息。可能是因为我使用的是较旧的Android Studio,所以我遇到了这个问题。我根据消息.

在gradle build中更新了Kotlin:1.4.32