前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【错误记录】Android Studio 编译报错 ( kotlin library {0} was compiled with a newer kotlin compiler and not b )

【错误记录】Android Studio 编译报错 ( kotlin library {0} was compiled with a newer kotlin compiler and not b )

作者头像
韩曙亮
发布2023-03-30 17:45:36
1.8K0
发布2023-03-30 17:45:36
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

一、报错信息


Android Studio 中打开 Kotlin 代码 , 报如下错误 :

在这里插入图片描述
在这里插入图片描述
代码语言:javascript
复制
kotlin library {0} was compiled with a newer kotlin compiler and not be read. 
Please update Kotlin plugin.

点击 Detail 查看详细情况 :

在这里插入图片描述
在这里插入图片描述

二、解决方案


方案一

执行

代码语言:javascript
复制
gradlew app:dependencies --configuration releaseRuntimeClasspath

命令 , 查询 依赖库情况 , 查询结果如下 :

代码语言:javascript
复制
D:\002_Project\002_Android_Learn\Componentization>gradlew app:dependencies --configuration releaseRuntimeClasspath
Starting a Gradle Daemon (subsequent builds will be faster)
WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: root project 'Componentization', project ':app', project ':base', ...

> Task :app:dependencies

------------------------------------------------------------
Project :app
------------------------------------------------------------

releaseRuntimeClasspath - Runtime classpath of compilation 'release' (target  (androidJvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10
|    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10
|    \--- org.jetbrains:annotations:13.0
+--- androidx.core:core-ktx:1.8.0
|    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    +--- androidx.core:core:1.8.0
|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
|    |    +--- androidx.annotation:annotation-experimental:1.1.0
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0
|    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.concurrent:concurrent-futures:1.0.0
|    |    |    +--- com.google.guava:listenablefuture:1.0
|    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.lifecycle:lifecycle-runtime:2.3.1 -> 2.5.1
|    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    +--- androidx.arch.core:core-common:2.1.0
|    |    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    +--- androidx.arch.core:core-runtime:2.1.0
|    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    \--- androidx.arch.core:core-common:2.1.0 (*)
|    |    |    \--- androidx.lifecycle:lifecycle-common:2.5.1
|    |    |         \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    \--- androidx.versionedparcelable:versionedparcelable:1.1.1
|    |         +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |         \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
+--- androidx.appcompat:appcompat:1.5.1
|    +--- androidx.activity:activity:1.5.1
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |    +--- androidx.core:core:1.8.0 (*)
|    |    +--- androidx.lifecycle:lifecycle-runtime:2.5.1 (*)
|    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1
|    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
|    |    |    \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1 (c)
|    |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1
|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |    |    +--- androidx.core:core-ktx:1.2.0 -> 1.8.0 (*)
|    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.5.1
|    |    |    |    +--- androidx.arch.core:core-common:2.1.0 (*)
|    |    |    |    +--- androidx.arch.core:core-runtime:2.1.0 (*)
|    |    |    |    \--- androidx.lifecycle:lifecycle-common:2.5.1 (*)
|    |    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1 (*)
|    |    |    +--- androidx.savedstate:savedstate:1.2.0
|    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    +--- androidx.arch.core:core-common:2.1.0 (*)
|    |    |    |    +--- androidx.lifecycle:lifecycle-common:2.4.0 -> 2.5.1 (*)
|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.20 -> 1.7.10 (*)
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
|    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1
|    |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1
|    |    |         |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1
|    |    |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1
|    |    |         |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1 (c)
|    |    |         |         |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1 (c)
|    |    |         |         |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1 (c)
|    |    |         |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0
|    |    |         |         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.0 -> 1.7.10 (*)
|    |    |         |         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0
|    |    |         |         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.0 -> 1.7.10 (*)
|    |    |         |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0 -> 1.7.10
|    |    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.1 (*)
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0 (*)
|    |    +--- androidx.savedstate:savedstate:1.2.0 (*)
|    |    +--- androidx.tracing:tracing:1.0.0
|    |    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*)
|    +--- androidx.annotation:annotation:1.3.0
|    +--- androidx.appcompat:appcompat-resources:1.5.1
|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |    +--- androidx.core:core:1.6.0 -> 1.8.0 (*)
|    |    +--- androidx.vectordrawable:vectordrawable:1.1.0
|    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    \--- androidx.collection:collection:1.1.0 (*)
|    |    +--- androidx.vectordrawable:vectordrawable-animated:1.1.0
|    |    |    +--- androidx.vectordrawable:vectordrawable:1.1.0 (*)
|    |    |    +--- androidx.interpolator:interpolator:1.0.0
|    |    |    |    \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |    |    \--- androidx.collection:collection:1.1.0 (*)
|    |    \--- androidx.appcompat:appcompat:1.5.1 (c)
|    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    +--- androidx.core:core:1.8.0 (*)
|    +--- androidx.core:core-ktx:1.8.0 (*)
|    +--- androidx.cursoradapter:cursoradapter:1.0.0
|    |    \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    +--- androidx.drawerlayout:drawerlayout:1.0.0 -> 1.1.1
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.core:core:1.2.0 -> 1.8.0 (*)
|    |    \--- androidx.customview:customview:1.1.0
|    |         +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |         +--- androidx.core:core:1.3.0 -> 1.8.0 (*)
|    |         \--- androidx.collection:collection:1.1.0 (*)
|    +--- androidx.emoji2:emoji2:1.2.0
|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
|    |    +--- androidx.collection:collection:1.1.0 (*)
|    |    +--- androidx.core:core:1.3.0 -> 1.8.0 (*)
|    |    +--- androidx.lifecycle:lifecycle-process:2.4.1
|    |    |    +--- androidx.lifecycle:lifecycle-runtime:2.4.1 -> 2.5.1 (*)
|    |    |    +--- androidx.startup:startup-runtime:1.1.1
|    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    \--- androidx.tracing:tracing:1.0.0 (*)
|    |    |    \--- androidx.annotation:annotation:1.2.0 -> 1.3.0
|    |    \--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1 (*)
|    +--- androidx.emoji2:emoji2-views-helper:1.2.0
|    |    +--- androidx.collection:collection:1.1.0 (*)
|    |    +--- androidx.core:core:1.3.0 -> 1.8.0 (*)
|    |    \--- androidx.emoji2:emoji2:1.2.0 (*)
|    +--- androidx.fragment:fragment:1.3.6
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.core:core:1.2.0 -> 1.8.0 (*)
|    |    +--- androidx.collection:collection:1.1.0 (*)
|    |    +--- androidx.viewpager:viewpager:1.0.0
|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    \--- androidx.customview:customview:1.0.0 -> 1.1.0 (*)
|    |    +--- androidx.loader:loader:1.0.0
|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0
|    |    |    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.1.0 (*)
|    |    |    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.0.0 -> 2.5.1 (*)
|    |    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.1.0 (*)
|    |    |    \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.5.1 (*)
|    |    +--- androidx.activity:activity:1.2.4 -> 1.5.1 (*)
|    |    +--- androidx.lifecycle:lifecycle-livedata-core:2.3.1 -> 2.5.1 (*)
|    |    +--- androidx.lifecycle:lifecycle-viewmodel:2.3.1 -> 2.5.1 (*)
|    |    +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1 -> 2.5.1 (*)
|    |    +--- androidx.savedstate:savedstate:1.1.0 -> 1.2.0 (*)
|    |    \--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
|    +--- androidx.lifecycle:lifecycle-runtime:2.5.1 (*)
|    +--- androidx.lifecycle:lifecycle-viewmodel:2.5.1 (*)
|    +--- androidx.resourceinspection:resourceinspection-annotation:1.0.1
|    |    \--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    +--- androidx.savedstate:savedstate:1.2.0 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10 (*)
|    \--- androidx.appcompat:appcompat-resources:1.5.1 (c)
+--- com.google.android.material:material:1.6.1
|    +--- androidx.annotation:annotation:1.2.0 -> 1.3.0
|    +--- androidx.appcompat:appcompat:1.1.0 -> 1.5.1 (*)
|    +--- androidx.cardview:cardview:1.0.0
|    |    \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    +--- androidx.coordinatorlayout:coordinatorlayout:1.1.0
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    +--- androidx.customview:customview:1.0.0 -> 1.1.0 (*)
|    |    \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    +--- androidx.constraintlayout:constraintlayout:2.0.1 -> 2.1.4
|    |    +--- androidx.appcompat:appcompat:1.2.0 -> 1.5.1 (*)
|    |    +--- androidx.core:core:1.3.2 -> 1.8.0 (*)
|    |    \--- androidx.constraintlayout:constraintlayout-core:1.0.4
|    +--- androidx.core:core:1.5.0 -> 1.8.0 (*)
|    +--- androidx.drawerlayout:drawerlayout:1.1.1 (*)
|    +--- androidx.dynamicanimation:dynamicanimation:1.0.0
|    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |    \--- androidx.legacy:legacy-support-core-utils:1.0.0
|    |         +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |         +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |         +--- androidx.documentfile:documentfile:1.0.0
|    |         |    \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |         +--- androidx.loader:loader:1.0.0 (*)
|    |         +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
|    |         |    \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    |         \--- androidx.print:print:1.0.0
|    |              \--- androidx.annotation:annotation:1.0.0 -> 1.3.0
|    +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
|    +--- androidx.fragment:fragment:1.2.5 -> 1.3.6 (*)
|    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.5.1 (*)
|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.1.0
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    +--- androidx.customview:customview:1.0.0 -> 1.1.0 (*)
|    |    \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    +--- androidx.transition:transition:1.2.0
|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    +--- androidx.core:core:1.0.1 -> 1.8.0 (*)
|    |    \--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    +--- androidx.vectordrawable:vectordrawable:1.1.0 (*)
|    \--- androidx.viewpager2:viewpager2:1.0.0
|         +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|         +--- androidx.fragment:fragment:1.1.0 -> 1.3.6 (*)
|         +--- androidx.recyclerview:recyclerview:1.1.0 (*)
|         +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|         \--- androidx.collection:collection:1.1.0 (*)
+--- androidx.constraintlayout:constraintlayout:2.1.4 (*)
\--- com.alibaba:arouter-api:1.5.1
     +--- com.alibaba:arouter-annotation:1.0.6
     \--- androidx.legacy:legacy-support-v4:1.0.0
          +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          +--- androidx.media:media:1.0.0
          |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
          |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          |    \--- androidx.versionedparcelable:versionedparcelable:1.0.0 -> 1.1.1 (*)
          +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
          +--- androidx.legacy:legacy-support-core-ui:1.0.0
          |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
          |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          |    +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
          |    +--- androidx.customview:customview:1.0.0 -> 1.1.0 (*)
          |    +--- androidx.viewpager:viewpager:1.0.0 (*)
          |    +--- androidx.coordinatorlayout:coordinatorlayout:1.0.0 -> 1.1.0 (*)
          |    +--- androidx.drawerlayout:drawerlayout:1.0.0 -> 1.1.1 (*)
          |    +--- androidx.slidingpanelayout:slidingpanelayout:1.0.0
          |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
          |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          |    |    \--- androidx.customview:customview:1.0.0 -> 1.1.0 (*)
          |    +--- androidx.interpolator:interpolator:1.0.0 (*)
          |    +--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0
          |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
          |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          |    |    \--- androidx.interpolator:interpolator:1.0.0 (*)
          |    +--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0
          |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.3.0
          |    |    \--- androidx.core:core:1.0.0 -> 1.8.0 (*)
          |    \--- androidx.cursoradapter:cursoradapter:1.0.0 (*)
          \--- androidx.fragment:fragment:1.0.0 -> 1.3.6 (*)

(c) - dependency constraint
(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 9s
1 actionable task: 1 executed

其中涉及到 org.jetbrains.kotlin:kotlin-stdlib:1.7.10 依赖库 ,

代码语言:javascript
复制
releaseRuntimeClasspath - Runtime classpath of compilation 'release' (target  (androidJvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.7.10
|    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10
|    \--- org.jetbrains:annotations:13.0

对应的 Gradle 脚本的配置为 :

代码语言:javascript
复制
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

其中 $kotlin_version 是定义在根目录 build.gradle 中的扩展变量

代码语言:javascript
复制
buildscript {
    ext.kotlin_version = "1.7.10"
}

这是由于 Android Studio 中的 Kotlin 插件版本太低 , 当前的 Kotlin 版本 1.7.10 太高导致的 ;

在根目录的 build.gradle 顶层构建脚本中 , 降低 Kotlin 的版本 , 即可解决上述问题 ; 这里降低到 1.5.1 即可 ;

代码语言:javascript
复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.7.10"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.1"
        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
    }
}

改为

代码语言:javascript
复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.5.1"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.1"
        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
    }
}

方案二

点击 " Update plugin " 按钮 , 升级 Kotlin 插件 ;

在这里插入图片描述
在这里插入图片描述

然后系统会自动下载插件 ;

在这里插入图片描述
在这里插入图片描述

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-11-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、报错信息
  • 二、解决方案
    • 方案一
      • 方案二
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档