无法解决有关向后兼容库的问题

Cannot resolve issue regarding backward compatibility library

我有 Android Studio 3.1.2 最新更新。

如图所示,我遇到了向后兼容性问题

下面是我的 gradle 文件

Gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.companyname.appname"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    testCompile 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.android.support:cardview-v7:27.1.1'

    implementation 'com.google.android.gms:play-services:9.2.0'
    implementation files('libs/ksoap2-android-assembly-2.4-jar-with-dependencies.jar')
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
        transitive = true;
    }
    implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'


}

以上是我的 gradle 文件,我没有按照错误中的说明使用库,仍然出现错误。

这是您的依赖项列表中的另一个库,它导入了指定的支持库。因为这些库依赖项会发生冲突,所以您必须明确添加它们。所以你必须将 mediarouter-v7:27.1.1 添加到你的依赖项中,消息就会消失。您可能还必须添加其他依赖项。

这个解决方案有点苦涩,因为你必须添加依赖项,你实际上并不需要。您可以尝试找出哪个库实际使用过时的版本 23.0.0 并要求他们将库更新到更新的版本。

也许是这个库:

implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'

这取决于

compile 'com.android.support:appcompat-v7:23.1.1'

因此,如他们网站上所述,您必须排除这些库:

If you have appcompat-v7 in your dependencies make sure to exclude it :

compile ('com.weiwangcn.betterspinner:library:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7' }

更新

我在使用 Google Wear OS 时再次遇到这个问题后,显示依赖关系树以进行追踪很有帮助,哪个依赖关系实际上包含冲突的库:

./gradlew app:dependencies

这会打印出完整的依赖关系图,您可以在其中看到相应的依赖关系。之后,您可以从使用旧引用的库中排除那些。