Android dependency 'com.android.support:support-support-v4' has different version
for the compile (23.1.1) and runtime (27.1.0) classpath.
You should manually set the same version via DependencyResolution.
我这里是引用了不同版本的v4包造成的。
Android Studio Terminal
窗口输入命令.\gradlew app:dependencies > dependencies.txt
可以查看Library引用情况
会生成文件dependencies.txt
到项目根目录,把项目从Android
切换到Project
即可看到。格式如下
+--- com.squareup.retrofit2:retrofit:2.8.2
| \--- com.squareup.okhttp3:okhttp:3.14.9
| \--- com.squareup.okio:okio:1.17.2 -> 2.6.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.70 -> 1.4.0 (*)
| \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70 -> 1.4.0
以retrofit2
中的okhttp3
举例,用以下方法排除
com.squareup.okhttp3:okhttp:3.14.9
group为com.squareup.okhttp3
, module为okhttp
implementation("com.squareup.retrofit2:retrofit:2.8.2") {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
如果实在是不知道哪个Library引用的,可以用下面这个方法,放在project 的build.gradle 下
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& details.requested.module == 'support-support-v4') {
details.useVersion '27.1.0'//改这个版本号到你想要的版本
}
}
}
}
具体位置示例
buildscript {
dependencies {
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
mavenCentral()
maven { url 'https://maven.google.com' }
google()
}
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& details.requested.module == 'support-support-v4') {
details.useVersion toolVersion
}
}
}
}