"所有的android库必须使用完全相同的版本"警告虽然它们是相同的

时间:2018-01-30 13:11:07

标签: android android-recyclerview build.gradle android-glide

我想在更新后尝试将 Glide 库从 3.8.0 迁移到 4.5.0 ,我会收到此警告:

  

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

我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "maa.myapp"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 45
        versionName "4.1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}
android {
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}
dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //notifications
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.chrisbanes:PhotoView:2.1.3'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.5.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    compile 'com.google.android.gms:play-services-ads:11.8.0'
    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
    compile 'com.firebase:firebase-jobdispatcher:0.6.0'
    compile 'com.vodyasov:amr:0.5'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
    compile 'com.google.guava:guava:23.6-android'
    testCompile 'junit:junit:4.12'
    compile 'com.squareup:otto:1.3.8'
}
apply plugin: 'com.google.gms.google-services'

4 个答案:

答案 0 :(得分:2)

如果您不想迁移到支持库27,则应从Glide中排除支持库

dependencies {
   compile ("com.github.bumptech.glide:glide:4.5.0") {
          exclude group: "com.android.support"
   }
   ...
}

来自Glide文档:

  

支持库版本 - Glide使用支持库版本27.

     

如果您需要或希望使用不同版本的支持   库你应该排除" com.android.support"来自你的Glide   build.gradle文件中的依赖项。

答案 1 :(得分:1)

运行gradlew app:dependencies命令,你得到以下输出。

  
    

+ --- com.google.firebase:firebase-appindexing:11.8.0 | + --- com.google.android.gms:play-services-base:11.8.0 | | + ---     com.google.android.gms:play-services-basement:11.8.0 | | |
    + --- com.android.support:support-v4:25.2.0 | | | | + --- com.android.support:support-compat:25.2.0 - > 27.0.1()| | |
    | + --- com.android.support:support-media-compat:25.2.0 | | |     | | + --- com.android.support:support-annotations:25.2.0 - >     27.0.1 | | | | | --- com.android.support:support-compat:25.2.0 - > 27.0.1(
)| | |
    | + --- com.android.support:support-core-utils:25.2.0 - > 27.0.1()     | | | | + --- com.android.support:support-core-ui:25.2.0 - >     27.0.1()| | | | --- com.android.support:support-fragment:25.2.0 - > 27.0.1(*)| | |     --- com.google.android.gms:play-services-basement-license:11.8.0 |
    | + --- com.google.android.gms:play-services-tasks:11.8.0

  

请注意firebase中支持库的版本差异。

  

com.android.support:support-compat:25.2.0 - > 27.0.1(*)

您可以看到所有库版本不匹配,因此,要解决此问题,您可以在下面的步骤中重复所有不匹配的库版本

替换此compile 'com.github.bumptech.glide:glide:4.5.0'

以下代码

compile ('com.github.bumptech.glide:glide:4.5.0',{
    exclude group: 'com.android.support'   
})

答案 2 :(得分:0)

当在同一个项目中引用库但具有不同版本时会出现此警告。

现在深入了解项目正在使用哪些不同版本的库,只需运行以下命令,您将获得完整的依赖树:

./gradlew app:dependencies

答案 3 :(得分:0)

随着Glide 4.0.0 RC0的发布,滑动开始使用支持库版本27.目前,Glide的稳定版本是Glide 4.5.0,它正在使用以下依赖项,

com.android.support:support-annotations:27.0.2
com.android.support:support-compat:27.0.2
com.android.support:support-core-ui:27.0.2
com.android.support:support-core-utils:27.0.2
com.android.support:support-fragment:27.0.2

此依赖关系来自支持库版本27,而您使用支持版本26.这就是Android SDK显示警告的原因,因为Glide 4.5.0在内部使用支持库版本27.

现在有两种解决方案,您在项目中使用支持库版本27或从Glide中排除支持库版本,

dependencies {
   compile ("com.github.bumptech.glide:glide:4.5.0") {
          exclude group: "com.android.support"
}