android - 库必须使用相同的版本错误

标签 android android-studio build.gradle android-support-library

每当我将 Glide 库添加到 app.gradle 时,我都会遇到这个错误,而且我无法摆脱它。

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:support-compat:27.1.1 and com.android.support:animated-vector-drawable:26.1.0 less... (Ctrl+F1)

There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)

构建文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.david.six_month"
        minSdkVersion 15
        multiDexEnabled true
        targetSdkVersion 26
        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:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'


    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'commons-net:commons-net:3.6'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}

最佳答案

将此添加到您的项目级别 build.gradle 文件,它将强制所有 android 支持库使用相同的版本

allprojects {
    ...

    configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support') {
                details.useVersion 'your library version here'
            }
        }
    }
}

关于android - 库必须使用相同的版本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49893572/

相关文章:

android - Gradle 抛出应用程序 :mergedebugresources exception

android - 如何在android中的textview中设置双文本样式?

android - Google Play Services如何弹出Enable Bluetooth提示?

Android 共享首选项在删除文件后仍然可见

javascript - 有没有办法从 native 代码检测 Phonegap 的设备就绪事件?

java - DatepickerDialog 未在 Textview 中添加日期

java - 文件实用程序 : readLines and writeLines methods not found

android - 使用 build.gradle 文件将 Eclipse 项目导入 Android Studio 失败

gradle - 为什么gradle不打印属性文件?

android - 找不到 com.squareup.picasso :picasso:2. 5.2