appcompat-v7:27.1.1与play-services:11.0.1版本冲突求助
解决Android Support库版本冲突问题
这个问题我碰到过好多次了,核心原因是你添加的com.google.android.gms:play-services:11.0.1内部依赖了旧版本(26.1.0)的Android Support库,而你的项目已经明确使用了27.1.1版本的Support库,两者版本不一致触发了Gradle的版本冲突检测(这个检测是为了避免运行时崩溃,非常有必要)。
下面给你两种解决方案,优先推荐第二种更优雅的方式:
方案一:强制统一所有Support库版本
在你的build.gradle文件的android代码块下方,添加一个configurations.all配置,强制指定所有Support库使用27.1.1版本,Gradle会自动替换所有第三方依赖中的旧版本:
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.example.boulbabazitouni.getdevicelocation_time" 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' } } // 添加这段配置强制统一Support库版本 configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '27.1.1' } } } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:support-vector-drawable:27.1.1' implementation 'com.android.support:mediarouter-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.google.android.gms:play-services:11.0.1' }
方案二:优化Play Services依赖(推荐)
你当前依赖的是整个play-services包,它包含了所有Google Play服务模块(比如定位、地图、支付等),体积非常大,而且容易引入不必要的依赖冲突。建议只依赖你实际需要的模块,比如如果你的应用是做定位功能,就替换成play-services-location:11.0.1:
修改dependencies中的Play Services依赖:
// 替换原来的完整play-services依赖 implementation 'com.google.android.gms:play-services-location:11.0.1'
这样不仅能减少APK体积,还能从根源上减少依赖冲突的概率——因为你只引入了需要的模块,不会带入其他模块的旧版本Support库依赖。
额外说明
如果你不确定自己需要哪个Play Services模块,可以根据应用功能查找对应的模块名,比如地图功能用play-services-maps,身份验证用play-services-auth等。
内容的提问来源于stack exchange,提问作者Sheakspear Zitouni
相关产品推荐
相关产品推荐

