android Kotlin库是用较新的Kotlin编译器编译的,无法读取

ryhaxcpt  于 2024-01-04  发布在  Android
关注(0)|答案(4)|浏览(163)

您好,我尝试在Android Studio(版本4.1)上运行Kotlin文件,但遇到错误:Kotlin库{0}是使用较新的Kotlin编译器编译的,无法读取。请更新Kotlin插件。
即使我得到了这个错误,我也可以运行Kotlin文件,但IDE在我使用Kotlin函数和方法时不给我提示,方法用红色标记。Gradle中的Kotlin版本是1.6.0,如果我返回到旧版本,我可以看到关于方法名称的提示,红色不显示。Gradle构建(应用程序):

  1. plugins {
  2. id 'com.android.application'
  3. id 'kotlin-android'
  4. }
  5. android {
  6. compileSdkVersion 31
  7. buildToolsVersion "30.0.3"
  8. defaultConfig {
  9. applicationId "com.example.kotlin_udemy4"
  10. minSdkVersion 26
  11. targetSdkVersion 31
  12. versionCode 1
  13. versionName "1.0"
  14. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  15. }
  16. buildTypes {
  17. release {
  18. minifyEnabled false
  19. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  20. }
  21. }
  22. compileOptions {
  23. sourceCompatibility JavaVersion.VERSION_1_8
  24. targetCompatibility JavaVersion.VERSION_1_8
  25. }
  26. kotlinOptions {
  27. jvmTarget = '1.8'
  28. }
  29. }
  30. dependencies {
  31. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  32. implementation 'androidx.core:core-ktx:1.7.0'
  33. implementation 'androidx.appcompat:appcompat:1.4.2'
  34. implementation 'com.google.android.material:material:1.6.1'
  35. testImplementation 'junit:junit:4.+'
  36. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  37. androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
  38. }

字符串
Gradle构建:

  1. // Top-level build file where you can add configuration options common to all sub-projects/modules.
  2. buildscript {
  3. ext.kotlin_version = "1.6.0"
  4. repositories {
  5. google()
  6. jcenter()
  7. }
  8. dependencies {
  9. classpath "com.android.tools.build:gradle:4.1.0"
  10. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  11. // NOTE: Do not place your application dependencies here; they belong
  12. // in the individual module build.gradle files
  13. }
  14. }
  15. allprojects {
  16. repositories {
  17. google()
  18. jcenter()
  19. }
  20. }
  21. task clean(type: Delete) {
  22. delete rootProject.buildDir
  23. }


有人知道如何解决这个问题吗?

baubqpgj

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。就是这样。
也许你可以试试这种方式。

disho6za

disho6za2#

除了Kotlin版本1.6.21.
该版本的Android Studio似乎相当过时;例如.当前版本“花栗鼠”使用:

  • com.android.tools.build:gradle:7.2.1
  • jcenter()应替换为mavenCentral()
  • 使用JavaVersion.VERSION_11
uqcuzwp8

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. // change to the new one
  2. classpath "com.android.tools.build:gradle:7.2.2"
  3. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"

字符串
}
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
如果您不确定新版本,请在以前的版本上滚动鼠标,新版本将突出显示,您可以相应地更新

展开查看全部
vom3gejh

vom3gejh4#

在问题弹出窗口旁边,我选择了“详细信息”链接,并有关于预期版本的信息。可能是因为我使用的是较旧的Android Studio,所以我遇到了这个问题。我根据消息.

在gradle build中更新了Kotlin:1.4.32

相关问题