问题
构建的时候会有个警告
> Task :app:compileDebugKotlin
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/mnt/ssd/Android/gradle/caches/transforms-3/fb6b451d2597b699984189cb6a3c60b0/transformed/jetified-kotlin-stdlib-jdk8-1.4.10.jar (version 1.4)
/mnt/ssd/Android/gradle/caches/transforms-3/c12ab5ef78460ecec6f166c920be19b4/transformed/jetified-kotlin-stdlib-jdk7-1.4.10.jar (version 1.4)
/mnt/ssd/Android/gradle/caches/transforms-3/add5ee3bbb24989fb64beaf861b7f2cb/transformed/jetified-kotlin-stdlib-1.5.31.jar (version 1.5)
/mnt/ssd/Android/gradle/caches/transforms-3/75fd3b264c1ce62db9b1af380b3ba3ea/transformed/jetified-kotlin-stdlib-common-1.5.31.jar (version 1.5)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
Android如何指定kotlin版本
根目录的build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0"
}
}
参考Dependency on the standard library added by default,不需要在每个模块
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.0"
这里指定kotlin的版本是1.4.0,但是看上面的报错版本是1.4.10和1.5.31,这是为什么呢
版本依赖关系
执行下面的命令看看debug的依赖
./gradlew :app:dependencies -q --configuration debugRuntimeClasspath
结果如下
------------------------------------------------------------
Project ':app'
------------------------------------------------------------
debugRuntimeClasspath - Runtime classpath of compilation 'debug' (target (androidJvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 -> 1.5.31
| +--- org.jetbrains:annotations:13.0
| --- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31
+--- androidx.core:core-ktx:1.1.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.31 -> 1.5.31 (*)
| +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| --- androidx.core:core:1.1.0 -> 1.6.0
| +--- androidx.annotation:annotation:1.2.0
| +--- androidx.annotation:annotation-experimental:1.1.0
| +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.1.0
| | +--- androidx.lifecycle:lifecycle-common:2.1.0
| | | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | +--- androidx.arch.core:core-common:2.1.0
| | | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| +--- androidx.versionedparcelable:versionedparcelable:1.1.1
| | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | --- androidx.collection:collection:1.0.0 -> 1.1.0
| | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| --- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
+--- com.ironsource.sdk:mediationsdk:7.2.1.1
| --- org.jetbrains.kotlin:kotlin-stdlib:1.4.32 -> 1.5.31 (*)
+--- androidx.constraintlayout:constraintlayout:2.1.4
| +--- androidx.appcompat:appcompat:1.2.0
| | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | +--- androidx.core:core:1.3.0 -> 1.6.0 (*)
| | +--- androidx.cursoradapter:cursoradapter:1.0.0
| | | --- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- androidx.fragment:fragment:1.1.0
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | +--- androidx.core:core:1.1.0 -> 1.6.0 (*)
| | | +--- androidx.collection:collection:1.1.0 (*)
| | | +--- androidx.viewpager:viewpager:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | | --- androidx.customview:customview:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | --- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | +--- androidx.loader:loader:1.0.0
| | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | | +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.1.0
| | | | | +--- androidx.arch.core:core-runtime:2.1.0
| | | | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | | | --- androidx.arch.core:core-common:2.1.0 (*)
| | | | | +--- androidx.lifecycle:lifecycle-livedata-core:2.1.0
| | | | | | +--- androidx.lifecycle:lifecycle-common:2.1.0 (*)
| | | | | | +--- androidx.arch.core:core-common:2.1.0 (*)
| | | | | | --- androidx.arch.core:core-runtime:2.1.0 (*)
| | | | | --- androidx.arch.core:core-common:2.1.0 (*)
| | | | --- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.1.0
| | | | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | +--- androidx.activity:activity:1.0.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- androidx.core:core:1.1.0 -> 1.6.0 (*)
| | | | +--- androidx.lifecycle:lifecycle-runtime:2.1.0 (*)
| | | | +--- androidx.lifecycle:lifecycle-viewmodel:2.1.0 (*)
| | | | --- androidx.savedstate:savedstate:1.0.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- androidx.arch.core:core-common:2.0.1 -> 2.1.0 (*)
| | | | --- androidx.lifecycle:lifecycle-common:2.0.0 -> 2.1.0 (*)
| | | --- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.1.0 (*)
| | +--- androidx.appcompat:appcompat-resources:1.2.0
| | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.1 -> 1.6.0 (*)
| | | +--- androidx.vectordrawable:vectordrawable:1.1.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- androidx.core:core:1.1.0 -> 1.6.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.2.0
| | | --- androidx.collection:collection:1.1.0 (*)
| | +--- androidx.drawerlayout:drawerlayout:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | --- androidx.customview:customview:1.0.0 (*)
| | --- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| +--- androidx.core:core:1.3.2 -> 1.6.0 (*)
| --- androidx.constraintlayout:constraintlayout-core:1.0.4
+--- com.google.ads.mediation:adcolony:4.7.0.0
| +--- com.adcolony:sdk:4.7.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.31 (*)
| | --- com.google.android.gms:play-services-appset:16.0.0
| | +--- com.google.android.gms:play-services-base:17.6.0
| | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | +--- androidx.core:core:1.2.0 -> 1.6.0 (*)
| | | +--- androidx.fragment:fragment:1.0.0 -> 1.1.0 (*)
| | | +--- com.google.android.gms:play-services-basement:17.6.0
| | | | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | | | +--- androidx.core:core:1.2.0 -> 1.6.0 (*)
| | | | --- androidx.fragment:fragment:1.0.0 -> 1.1.0 (*)
| | | --- com.google.android.gms:play-services-tasks:17.2.1
| | | --- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | --- com.google.android.gms:play-services-tasks:17.0.0 -> 17.2.1 (*)
| +--- androidx.annotation:annotation:1.2.0
| --- com.google.android.gms:play-services-ads:20.6.0
| +--- androidx.browser:browser:1.0.0
| | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- androidx.interpolator:interpolator:1.0.0 (*)
| | +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| | --- androidx.legacy:legacy-support-core-ui:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | +--- androidx.legacy:legacy-support-core-utils:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | +--- androidx.documentfile:documentfile:1.0.0
| | | | --- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.loader:loader:1.0.0 (*)
| | | +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
| | | | --- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | --- androidx.print:print:1.0.0
| | | --- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- androidx.customview:customview:1.0.0 (*)
| | +--- androidx.viewpager:viewpager:1.0.0 (*)
| | +--- androidx.coordinatorlayout:coordinatorlayout:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | --- androidx.customview:customview:1.0.0 (*)
| | +--- androidx.drawerlayout:drawerlayout:1.0.0 (*)
| | +--- androidx.slidingpanelayout:slidingpanelayout:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | --- androidx.customview:customview:1.0.0 (*)
| | +--- androidx.interpolator:interpolator:1.0.0 (*)
| | +--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | | --- androidx.interpolator:interpolator:1.0.0 (*)
| | +--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | --- androidx.core:core:1.0.0 -> 1.6.0 (*)
| | --- androidx.cursoradapter:cursoradapter:1.0.0 (*)
| +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
| +--- androidx.core:core:1.0.0 -> 1.6.0 (*)
| +--- com.google.android.gms:play-services-ads-base:20.6.0
| | --- com.google.android.gms:play-services-basement:17.6.0 (*)
| +--- com.google.android.gms:play-services-ads-identifier:17.0.0
| | --- com.google.android.gms:play-services-basement:17.0.0 -> 17.6.0 (*)
| +--- com.google.android.gms:play-services-ads-lite:20.6.0
| | +--- androidx.work:work-runtime:2.7.0
| | | +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
| | | +--- com.google.guava:listenablefuture:1.0
| | | +--- androidx.lifecycle:lifecycle-livedata:2.1.0 (*)
| | | +--- androidx.startup:startup-runtime:1.0.0
| | | | +--- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | --- androidx.tracing:tracing:1.0.0
| | | | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | +--- androidx.core:core:1.6.0 (*)
| | | +--- androidx.room:room-runtime:2.2.5
| | | | +--- androidx.room:room-common:2.2.5
| | | | | --- androidx.annotation:annotation:1.1.0 -> 1.2.0
| | | | +--- androidx.sqlite:sqlite-framework:2.0.1 -> 2.1.0
| | | | | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | | --- androidx.sqlite:sqlite:2.1.0
| | | | | --- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | | | +--- androidx.sqlite:sqlite:2.0.1 -> 2.1.0 (*)
| | | | --- androidx.arch.core:core-runtime:2.0.1 -> 2.1.0 (*)
| | | +--- androidx.sqlite:sqlite:2.1.0 (*)
| | | +--- androidx.sqlite:sqlite-framework:2.1.0 (*)
| | | +--- androidx.core:core:1.1.0 -> 1.6.0 (*)
| | | --- androidx.lifecycle:lifecycle-service:2.1.0
| | | --- androidx.lifecycle:lifecycle-runtime:2.1.0 (*)
| | +--- com.google.android.gms:play-services-ads-base:20.6.0 (*)
| | +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| | +--- com.google.android.gms:play-services-measurement-sdk-api:18.0.3
| | | +--- com.google.android.gms:play-services-basement:17.0.0 -> 17.6.0 (*)
| | | --- com.google.android.gms:play-services-measurement-base:18.0.3
| | | --- com.google.android.gms:play-services-basement:17.0.0 -> 17.6.0 (*)
| | --- com.google.android.ump:user-messaging-platform:1.0.0
| | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0
| | +--- com.google.android.gms:play-services-ads-identifier:17.0.0 (*)
| | --- com.google.android.gms:play-services-basement:17.0.0 -> 17.6.0 (*)
| +--- com.google.android.gms:play-services-appset:16.0.0 (*)
| +--- com.google.android.gms:play-services-basement:17.6.0 (*)
| --- com.google.android.gms:play-services-tasks:17.0.0 -> 17.2.1 (*)
+--- com.squareup.okhttp3:logging-interceptor:4.9.0
| +--- com.squareup.okhttp3:okhttp:4.9.0
| | +--- com.squareup.okio:okio:2.8.0
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 -> 1.5.31 (*)
| | | --- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0 -> 1.5.31
| | --- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.31 (*)
| --- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.31 (*)
| --- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10
| --- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.31 (*)
--- com.squareup.okhttp3:okhttp:4.9.0 (*)
(*) - dependencies omitted (listed previously)
A web-based, searchable dependency report is available by adding the --scan option.
我们这里分析一下我们指定的版本是1.4.0,为什么kotlin-stdlib、kotlin-stdlib-common版本最终变成了1.5.31,kotlin-stdlib-jdk7、kotlin-stdlib-jdk8版本为1.4.10
com.adcolony:sdk:4.7.0依赖的org.jetbrains.kotlin:kotlin-stdlib:1.5.31版本最高,同时也比我们指定的1.4.0高,所以确定了kotlin-stdlib的版本为1.5.31,同时导致kotlin-stdlib-common的版本也是1.5.31
com.squareup.okhttp3:logging-interceptor:4.9.0依赖的org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10只有一个版本,同时也比我们指定的1.4.0高,所以确定了kotlin-stdlib-jdk8版本为1.4.10,同时也导致kotlin-stdlib-jdk7版本为1.4.10
提升kotlin版本
所以解决方案就比较简单了,提升下kotlin版本到1.5.0试试
org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31
org.jetbrains.kotlin:kotlin-stdlib:1.5.31
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.0
这时候虽然看起来还是不统一,但是没有警告了,问题解决
提升下kotlin版本到1.5.31试试
org.jetbrains.kotlin:kotlin-stdlib:1.5.31
org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31