android中gradle 3.1.4 处理com.android.support libraries版本不一致冲突问题

在添加依赖的时候,由于可能使用的第三方库依赖了相同的库,但是版本不同,会报错提示版本不一致

比如这里我添加了permissionsDispatcher的依赖,导致com.android.support报错提示如下

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 27.0.2. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:27.0.2 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

可以看到是因为项目com.android.support库版本为27.1.1,第三方库里面是27.0.2,所以用以下方式将冲突的包剔除,统一使用项目的版本

implementation ("com.github.hotchemi:permissionsdispatcher:3.3.1"){
    exclude group: 'com.android.support',module:'support-media-compat'
    exclude group: 'com.android.support',module:'support-v13'
}

这里使用 exclude 剔除 'com.android.support'库里的冲突模块 'support-media-compat' 和 'support-v13',再build一次就不再报错冲突了。

注意:这种方式剔除模块原本依赖的库,可能会出现因为版本不同而产生的问题,要确保可以使用同一版本的依赖

猜你喜欢

转载自blog.csdn.net/github_33420275/article/details/82757515