Glide从3.8.0迁移至4.5.0后出现com.android.support版本不一致警告
解决Glide 4.5.0迁移时的Support库版本冲突警告
嘿,这个问题我之前迁移Glide的时候也碰到过!警告里说得很明白——你项目里的Android Support库版本混着用了:Glide 4.5.0内部依赖的是com.android.support:support-compat:27.0.2,但你手动声明的所有Support库(比如appcompat-v7、recyclerview-v7这些)都是26.1.0版本,版本不一致就会触发这个警告,严重的话还可能导致运行时崩溃。
下面给你两种可行的解决方案:
方案一:升级项目到匹配Glide的Support库版本
这是最推荐的做法,直接把项目的编译版本和所有Support库统一升级到27.0.2,和Glide的依赖对齐:
修改你的Module级别build.gradle:
apply plugin: 'com.android.application' android { compileSdkVersion 27 // 升级为27 buildToolsVersion '27.0.3' // 对应27版本的buildTools dexOptions { preDexLibraries = false javaMaxHeapSize "4g" } defaultConfig { applicationId "maa.myapp" minSdkVersion 15 targetSdkVersion 27 // 同步升级为27 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' }) // 所有Support库版本统一改为27.0.2 compile 'com.android.support:recyclerview-v7:27.0.2' compile 'com.android.support:appcompat-v7:27.0.2' compile 'com.android.support:design:27.0.2' compile 'com.github.chrisbanes:PhotoView:2.1.3' compile 'com.android.support:cardview-v7:27.0.2' compile 'com.android.volley:volley:1.0.0' compile 'com.android.support:multidex:1.0.2' compile 'com.android.support:support-v4:27.0.2' 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'
方案二:强制Glide使用你项目的26.1.0版本Support库
如果暂时不想升级compileSdk到27,可以通过Gradle的依赖解析策略,强制Glide使用26.1.0的Support库:
在你的android配置块里新增以下规则:
android { // 原有的packagingOptions、dexOptions等配置... configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' // 新增这两行,强制冲突的Support库使用26.1.0版本 resolutionStrategy.force 'com.android.support:support-compat:26.1.0' resolutionStrategy.force 'com.android.support:animated-vector-drawable:26.1.0' } }
这样就能让Glide的依赖和你项目的版本保持一致,快速消除警告。
小提醒:虽然方案二能临时解决问题,但长期来看还是推荐方案一,保持依赖版本统一能减少潜在的兼容性问题。
内容的提问来源于stack exchange,提问作者ali
相关产品推荐
相关产品推荐

