天天看點

Android dependency has different version for the compile

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
            }
        }
    }
}