【Android】kotlin jdk版本冲突与Kotlin依赖管理插件

1、androidx.activity:activity:1.8.0 依赖版本错误问题

*依赖项"androidx.activity:activity:1.8.0"要求依赖它的库和应用针对版本 34 或更高版本 Android API 进行编译。:app 目前是针对 android-33 编译的。此外,Android Gradle 插件 7.3.0 的最大推荐编译 SDK 版本为 33。*

复制代码
19 issues were found when checking AAR metadata:
​
  1.  Dependency 'androidx.activity:activity-ktx:1.8.0' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 7.4.2 is 33.
​
      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdkVerion of at least 34.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
  2.  Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 7.4.2 is 33.
​
      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdkVerion of at least 34.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
  3.  Dependency 'androidx.savedstate:savedstate-ktx:1.2.1' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Recommended action: Update this project to use a newer compileSdkVersion
      of at least 33, for example 33.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
  4.  Dependency 'androidx.savedstate:savedstate:1.2.1' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Recommended action: Update this project to use a newer compileSdkVersion
      of at least 33, for example 33.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
  5.  Dependency 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Recommended action: Update this project to use a newer compileSdkVersion
      of at least 33, for example 33.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
  6.  Dependency 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Recommended action: Update this project to use a newer compileSdkVersion
      of at least 33, for example 33.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
​
        .......
        .......
        .......
        .......
        .......
​
 19.  Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that
      depend on it to compile against version 33 or later of the
      Android APIs.
​
      :app is currently compiled against android-32.
​
      Recommended action: Update this project to use a newer compileSdkVersion
      of at least 33, for example 33.
​
      Note that updating a library or application's compileSdkVersion (which
      allows newer APIs to be used) can be done separately from updating
      targetSdkVersion (which opts the app in to new runtime behavior) and
      minSdkVersion (which determines which devices the app can be installed
      on).
解决方式:升级编译后的sdk版本

compileSdktargetSdk 设置为34或者更高版本

以上内容已经解决了,您的问题,下面内容可忽略!!!

以上内容已经解决了,您的问题,下面内容可忽略!!!

以上内容已经解决了,您的问题,下面内容可忽略!!!

2、 Kotlin 相关依赖库的版本冲突问题

【Android】报错内容 Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)

解决方式:添加Kotlin依赖管理插件 platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")

复制代码
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
复制代码
项目中引入 Kotlin 的依赖管理插件。其中 platform("org.jetbrains.kotlin:kotlin-bom:1.8.0") 的作用是引入 Kotlin 的 Bill of Materials(BOM),简化了 Kotlin 相关库的版本管理。通过引入 BOM,可以统一管理 Kotlin 相关库的版本,避免版本冲突和简化依赖配置。这样在引入其他 Kotlin 相关库时,可以不指定版本号,直接使用BOM中指定的版本。
相关推荐
沈询-阿里35 分钟前
java-智能识别车牌号_基于spring ai和开源国产大模型_qwen vl
java·开发语言
AaVictory.41 分钟前
Android 开发 Java中 list实现 按照时间格式 yyyy-MM-dd HH:mm 顺序
android·java·list
LuckyLay1 小时前
Spring学习笔记_27——@EnableLoadTimeWeaving
java·spring boot·spring
向阳12181 小时前
Dubbo负载均衡
java·运维·负载均衡·dubbo
Gu Gu Study1 小时前
【用Java学习数据结构系列】泛型上界与通配符上界
java·开发语言
似霰2 小时前
安卓智能指针sp、wp、RefBase浅析
android·c++·binder
大风起兮云飞扬丶2 小时前
Android——网络请求
android
干一行,爱一行2 小时前
android camera data -> surface 显示
android
WaaTong2 小时前
《重学Java设计模式》之 原型模式
java·设计模式·原型模式
m0_743048442 小时前
初识Java EE和Spring Boot
java·java-ee