Wonder4 Life

Android support libraries 版本冲突问题

今天创建新工程,在 gradle 脚本中遇到了错误提示:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.3.1, 24.0.0. Examples include com.android.support:animated-vector-drawable:25.3.1 and com.android.support:mediarouter-v7:24.0.0 more…

引入的 library 如下:

1
2
3
4
5
6
dependencies {
...
compile "com.android.support:appcompat-v7:25.3.1"
compile 'com.google.android.gms:play-services:10.2.1'
...
}

说明 play-services 10.2.1 版本的某个子包采用了 24.0.0 版本的 appcompat-v7,产生了版本冲突。具体可以通过如下命令查询库的依赖报告:

1
./gradlew -q dependencies app:dependencies --configuration compile

通过报告可以看出 play-services-ads 和 play-services-cast-framework 仍然使用较老的 24.0.0 版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
+--- com.google.android.gms:play-services-ads:10.2.1
| +--- com.google.android.gms:play-services-ads-lite:10.2.1
| | \--- com.google.android.gms:play-services-basement:10.2.1
| | \--- com.android.support:support-v4:24.0.0 -> 25.3.1 (*)
...
+--- com.google.android.gms:play-services-cast-framework:10.2.1
| +--- com.google.android.gms:play-services-base:10.2.1 (*)
| +--- com.google.android.gms:play-services-cast:10.2.1
| | +--- com.google.android.gms:play-services-base:10.2.1 (*)
| | +--- com.google.android.gms:play-services-basement:10.2.1 (*)
| | \--- com.android.support:mediarouter-v7:24.0.0
| | +--- com.android.support:palette-v7:24.0.0
| | | \--- com.android.support:support-v4:24.0.0 -> 25.3.1 (*)
| | \--- com.android.support:appcompat-v7:24.0.0 -> 25.3.1 (*)

解决方法是仅导入需要的 play-services 库,或者将 appcompat-v7 降到 24.0.0。

Reference

All com.android.support libraries must use the exact same version specification