今天升级一些插件版本后无法编译,发现kotlin jdk 1.8.20和kotlin jdk 1.6.21重复冲突,网上找了挺多方法都没生效,千回百转才解决,发出来希望可以帮助到同样报错的同学
报错
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:app:checkDebugDuplicateClasses’.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations ReflectSdkVersionfoundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk7−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk7:1.6.21)Duplicateclasskotlin.internal.jdk8.JDK8PlatformImplementationsfoundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.internal.jdk8.JDK8PlatformImplementations ReflectSdkVersion found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21) Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21) Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations ReflectSdkVersionfoundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk7−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk7:1.6.21)Duplicateclasskotlin.internal.jdk8.JDK8PlatformImplementationsfoundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.internal.jdk8.JDK8PlatformImplementationsReflectSdkVersion found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.io.path.ExperimentalPathApi found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.io.path.PathRelativizer found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.io.path.PathsKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.jdk7.AutoCloseableKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk7-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21)
Duplicate class kotlin.jvm.jdk8.JvmRepeatableKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.streams.jdk8.StreamsKt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.streams.jdk8.StreamsKt asSequence asSequence asSequence inlined inlined inlinedSequence 1foundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.streams.jdk8.StreamsKt 1 found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21) Duplicate class kotlin.streams.jdk8.StreamsKt 1foundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.streams.jdk8.StreamsKtasSequenceKaTeX parse error: Can't use function '$' in math mode at position 8: inlined$̲Sequence$2 foun…inlined$Sequence 3foundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.streams.jdk8.StreamsKt 3 found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21) Duplicate class kotlin.streams.jdk8.StreamsKt 3foundinmoduleskotlin−stdlib−1.8.20(org.jetbrains.kotlin:kotlin−stdlib:1.8.20)andkotlin−stdlib−jdk8−1.6.21(org.jetbrains.kotlin:kotlin−stdlib−jdk8:1.6.21)Duplicateclasskotlin.streams.jdk8.StreamsKtasSequence$ inlined inlined inlinedSequence$4 found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and kotlin-stdlib-jdk8-1.6.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21)
Go to the documentation to learn how to Fix dependency resolution errors.
方案
build.gradle文件中修改kotlin-stdlib-jdk加载方式
// 插件升级后出现kotlin-stdlib-jdk版本冲突在这里解决 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20")
来源地址:https://blog.csdn.net/LLCCQAQ/article/details/131120858