【问题标题】:Libraries must use same version error库必须使用相同的版本错误
【发布时间】:2018-09-28 08:00:25
【问题描述】:

每当我将 Glide 库添加到 app.gradle 时,我都会收到此错误,但我无法摆脱它。

所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.1.1、26.1.0。例子包括 com.android.support:support-compat:27.1.1 和 com.android.support:animated-vector-drawable:26.1.0 少... (Ctrl+F1)

有一些库或工具和库的组合, 不兼容,或者可能导致错误。一种这样的不兼容性是 使用不支持的 Android 支持库版本进行编译 最新版本(或者特别是低于您的 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'
}

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      似乎 Glide 正在使用更新版本的支持库。您可以将其余的支持库也添加到使用最新版本,或者如果由于其他原因您不能这样做,请从 Glide 库中排除支持库,如下所示:

      implementation ('com.github.bumptech.glide:glide:4.7.1', {
          exclude group: 'com.android.support'
      })
      
      annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
      

      【讨论】:

      • 这对我有用。我正要把头撞到墙上。除了最新的 glide 之外,我所有的库都是 26 个,并且我在 gradle 中遇到了错误和混合支持库。
      【解决方案3】:

      您需要有一个部分定义配置以强制执行需要使用的库的特定实现。例如,

      configurations.all {
          resolutionStrategy {
              force 'com.android.support:design:25.3.1'
              force 'com.android.support:support-v4:25.3.1'
              force 'com.android.support:appcompat-v7:25.3.1'
          }
      }
      

      【讨论】:

        【解决方案4】:

        例如你的错误:

        所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.1.1、26.1.0。例子包括 com.android.support:support-compat:27.1.1 和 com.android.support:animated-vector-drawable:26.1.0 少... (Ctrl+F1)

        *解决方案是像这样编译这些库的版本:

        implementation 'com.android.support:animated-vector-drawable:27.1.1'
        

        -如果另一个库有同样的问题并且有另一个版本,只需在您的支持下编译它:appcompat 版本

        这解决了我的问题,我希望它能解决你的问题。

        最好的祝愿:)

        【讨论】:

          【解决方案5】:

          我遇到了这个错误:

          所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.1.1、26.1.0。例子包括 com.android.support:animated-vector-drawable:27.1.1 和 com.android.support:support-media-compat:26.1.0

          然后我在build.gradle - Module:app 中添加了 Design 依赖,它解决了问题:

          implementation 'com.android.support:design:27.1.1'
          

          【讨论】:

            【解决方案6】:

            由于 Glide 库导致此错误。尝试 picasso 图像加载器或其他图像加载器

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2023-04-01
              • 1970-01-01
              • 2018-05-22
              • 1970-01-01
              • 1970-01-01
              • 2017-08-22
              • 1970-01-01
              相关资源
              最近更新 更多